[neon] No bean returned [message #1751359] |
Mon, 09 January 2017 06:08  |
Eclipse User |
|
|
|
I have a service class which is defined and used inside the scout server. The service class is annoted with @ApplicationScoped. However, when I try to use it BEANS.get() fails with an AssertionException, stating that no instance for that service class could be found.
Shouldn't the above annotation be enough to be able to resolve the bean?
|
|
|
|
|
|
|
|
|
|
|
|
Re: [neon] No bean returned [message #1751379 is a reply to message #1751378] |
Mon, 09 January 2017 10:18   |
Eclipse User |
|
|
|
Next update:
I changed my RemoteService as follows:
@ApplicationScoped
@TunnelToServer
public class RemoteService { // really implementing IRemoteService which is annotated :-)
public void executeAction() {
IBeanManager mgr = BEANS.getBeanManager();
List<IBean<ServerOnlyService>> beans = mgr.getRegisteredBeans(ServerOnlyService.class);
if (beans == null || beans.size() == 0) {
System.err.println("--- No ServerOnlyService beans registered, trying to manually register beans");
mgr.registerClass(ServerOnlyService.class);
} else {
System.out.println("--- Number of registered beans=" + beans.size());
}
BEANS.get(ServerOnlyService.class).doTheWork(); // now this line no longer causes an AssertionException
}
}
Now, on the first timed call, I get the syserr() line, telling me no beans were registered for ServerOnlyService but my manual registering of the class works, because the call to doTheWork() is now successfully called.
On all subsequent calls, I get the sysout() line, telling me that there is 1 bean registered.
So, for some reason, despite ServerOnlyService being annotated with @ApplicationScoped and being in the same app.server project (though in a different package), it is not automatically picked up by Jandex (as opposed to the RemoteService).
Are there any reasons that could cause this (other than the @IgnoreBean annotation, which we are not using)? Anything in my class that would make it "unpickupable" by Jandex?
|
|
|
|
|
|
|
Re: [neon] No bean returned [message #1751564 is a reply to message #1751524] |
Wed, 11 January 2017 09:14  |
Eclipse User |
|
|
|
Jérémie
Thanks for your follow-up. Interestingly enough, I can no longer reproduce the problem even in my production version.
HOWEVER:
Your last comment about the Jandex rebuild caused me to re-read Ivan's first post. I had misunderstood him the first time round, thinking that the rebuild took a certain time and my application tried to access it before the rebuild was finished. On second reading, I understood that I needed to enable the rebuild for my development version.
I have two setups for my server and ui projects: a Jetty based one (generated by the Scout SDK) and a tomcat based one. I mostly start the backend-server using the tomcat profile and the UI using Jetty. The jetty launchers already contain the jandex-rebuild property, BUT the tomcat launcher of course DID NOT. So I assume that this was the reason for this error. I guess that Jandex has some internal mechanism to occasionally rebuild its index and for some reason did so today, hence me not being able to reproduce the issue.
I have now also added the jandex-rebuild parameter to our tomcat profiles in the hope of avoiding such isses in the future.
Thanks to everyone for your help!
|
|
|
Powered by
FUDForum. Page generated in 0.08884 seconds