-
1. Re: Resource Injection in plain Java class fails
nickarls Nov 11, 2012 4:50 PM (in response to mylos78)Injection is not an automagic happening. The AS takes the servlet class and does all the injection for it (forcing it into the fields), that is why the "new" operator doesn't work with injection either.
If you want to separate the stuff, you could use CDI by adding an empty beans.xml, move logic to the JMSUtility and do an @Inject JMSUtility util; in the servlet class.
-
2. Re: Resource Injection in plain Java class fails
sfcoy Nov 11, 2012 6:13 PM (in response to mylos78)1 of 1 people found this helpfulAlternatively, you could add an @Stateless annotation to JMSUtility and inject it into your servlet with @Inject or @EJB.
JMS is a transactional resource, so this might be considered more appropriate than straight CDI.
Either way, the thing to remember is that you only get injection when the bean lifecycle is managed by the container.
-
3. Re: Resource Injection in plain Java class fails
nickarls Nov 12, 2012 1:46 AM (in response to sfcoy)True, and no need bringing in new technologies if you're not using it for anything else and it can be done with the existing stack. Although I don't think it matters in this case since the methods being called would still be the transactional ones and not the helper methods directly.
-
4. Re: Resource Injection in plain Java class fails
mylos78 Nov 12, 2012 3:06 AM (in response to nickarls)Thank you very much for the kind replies (both correct I guess so I had to pick up just the first reply as the correct one :-) )
Thats very clear, so it looks pretty the same as Spring container (where injections will not work if you are using the new operator for creating your beans).
Out of curiosity, am I allowed to install as module the POJO class (in the modules folder), with a beans.xml file in the JAR file, and then @Inject the JMSUtility class in my applications ?
Thanks & have a nice day
-
5. Re: Resource Injection in plain Java class fails
nickarls Nov 12, 2012 3:12 AM (in response to mylos78)There is a high change the CDI approach wouldn't work in that case since the visiblity rules of the EE deployment is followed, per spec, and the JBoss module is alien to the WAR archive (even if class visiblity is established to the JBoss Modules thanks to the AS)
-
6. Re: Resource Injection in plain Java class fails
mylos78 Nov 12, 2012 7:46 AM (in response to nickarls)Thanks. By the way I have just tried installing the Utility class as a module (without injections) but I get an error:
JBAS011843: Failed instantiate InitialContextFactory org.jboss.naming.remote.client.InitialContextFactory from classloader ModuleClassLoader for Module "org.jboss.as.connector:main" from local module loader @d9660d (roots: C:\jboss-as-7.1.1.Final\modules)
I will open another thread for this issue.
Regards
Mylos