On 24/02/2013 17:21, Scott Ferguson wrote: > On 2/24/13 2:06 AM, c.whalley wrote: >> On 24/02/2013 05:49, Dan Ziegelbein wrote: >>> The reason you're getting NPE's is that your instances of APICommand are >>> not themselves injected by the container (you are instantiating them in >>> code somewhere...indicated by the fact that APICommand has a >>> non-injected parameterized constructor). >>> >>> Dan >> Hi Dan & thanks for this, >> >> I looked more at this and realised I need to do as you say, and it seems >> I need Webbeans and the @Component annotation, plus token >> META-INF/web-beans.xml to mark it as so? If that's right, I'm now >> struggling to even get the @Component to resolve - does the webbeans >> package come with Resin or is it an external download? > For Resin 4.0, it's CDI and all the names changed: > > the magic file in META-INF/beans.xml in a jar or WEB-INF/beans.xml for > the WEB-INF/classes. The smallest content of that file "<beans/>". > > You don't need an annotation on the bean, but you can use something like > @javax.inject.Singleton if you want it to be a single instance. The > default behavior instantiates a new instance of your bean at each > @Inject point. > > -- Scott Umm ... I hope I read you right - I just added beans.xml to WEB-INF with just "<beans/>" as its content and that ut is still null. I did change it slightly from the code I posted earlier to ensure it really is a bean, in case that was significant:
public class APICommand implements Serializable { private static final long serialVersionUID = 1L; private static final Logger log = Logger.getLogger(APICommand.class.getName()); @PersistenceUnit(unitName="my_persistence_unit") private EntityManagerFactory emf; @Inject private UserTransaction ut; private EntityManager em; ... private void update(User user) { try { ut.begin(); em = emf.createEntityManager(); ... } } > >> -- Carl Whalley >> >> _______________________________________________ >> resin-interest mailing list >> resin-interest@caucho.com >> http://maillist.caucho.com/mailman/listinfo/resin-interest >> > > _______________________________________________ > resin-interest mailing list > resin-interest@caucho.com > http://maillist.caucho.com/mailman/listinfo/resin-interest > _______________________________________________ resin-interest mailing list resin-interest@caucho.com http://maillist.caucho.com/mailman/listinfo/resin-interest