-
-
2. Re: simplest possible servlet app
mikewse May 14, 2009 12:23 AM (in response to mikewse)If you mean @Named on MyService, it doesn't seem to make a difference?
BTW, here's the WebBeans stuff from the startup log:
INFO: Starting Servlet Engine: Apache Tomcat/6.0.18 ... INFO: Web Beans 1.0.0.CR1 INFO: Transactional services not available. Transactional observers will be invoked synchronously. INFO: EJB services not available. Session beans will be simple beans, injection into non-contextual EJBs, injection of @EJB in simple beans, injection of Java EE resources and JMS resources will not be available. INFO: JPA services not available. Injection of @PersistenceContext will not occur. Entity beans will be discovered as simple beans.
-
3. Re: simplest possible servlet app
nickarls May 14, 2009 7:55 AM (in response to mikewse)Looking at https://jira.jboss.org/jira/browse/WBINT-5 I would guess it's not yet supported (at least not on tomcat)
-
4. Re: simplest possible servlet app
mikewse May 15, 2009 12:10 AM (in response to mikewse)Right, yes.
Also, I saw this mention in the refguide :
Web Beans also supports Servlet injection in Tomcat. To enable this, place the webbeans-tomcat-support.jar in $TOMCATHOME/lib, and add the following to your META-INF/context.xml:<Listener className="org.jboss.webbeans.environment.tomcat.WebBeansLifecycleListener"> </Listener>
I guess there is some extra appserver magic needed to support servlet injection, therefore the special tomcat support file, so I'll stay away from that to keep my app simple and servlet container-agnostic...
What is the simplest way to get started with some injections in a pure servlet app? I tried to move my injection out from MyServlet to another class, which is new:ed from MyServlet.doGet, but I still only get null...?
mvh Mike (Mölnlycke ;-)
-
5. Re: simplest possible servlet app
gavin.king May 17, 2009 8:24 AM (in response to mikewse)
I tried to move my injection out from MyServlet to another class, which is new:ed from MyServlet.doGet, but I still only get null...?Injection doesn't apply to objects you instantiate using new. You have to obtain the object from the container, using BeanManager.getInstance().
-
6. Re: simplest possible servlet app
mikewse May 17, 2009 2:31 PM (in response to mikewse)
Gavin King wrote on May 17, 2009 08:24:
Injection doesn't apply to objects you instantiate using new. You have to obtain the object from the container, using BeanManager.getInstance().I was thinking about that route too, but the examples in the refguide suggest that I should have a manager instance injected by WebBeans like this:
@Current Manager manager;
which doesn't work as I don't have any contextual bean instance yet that can receive this injection.
Looking at the spec I see that looking up the Manager using JNDI is an alternative way. Is that my only option in this case?
-
7. Re: simplest possible servlet app
gavin.king May 17, 2009 6:04 PM (in response to mikewse)Until the functionality in WBINT-5 is implemented, yes.
-
8. Re: simplest possible servlet app
mikewse May 18, 2009 12:47 AM (in response to mikewse)I dug around a little in the sources, and am now successfully using
Manager manager = CurrentManager.rootManager();
to get the manager programatically. This ties my code to the JBoss RI but on the other hand lets me skip adding any container-specific JNDI setup (Tomcat's context.xml), which suits my demo examples fine.