Hi Everybody
Environment: java SE
For using CDI, I do:
WeldContainer weld = new Weld().initialize(); SomePojo p = weld.instance().select(SomePojo.class).get();
If SomePojo only includes @Inject annotations, it works. So far so good.
However
If SomePojo contains @Produces annotations (producer methods) then I get the following error:
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307) at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344) at javax.naming.InitialContext.rebind(InitialContext.java:427) at com.sun.jersey.server.impl.cdi.CDIExtension.initialize(CDIExtension.java:189) ... 54 more at org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:48) at org.jboss.weld.bootstrap.events.BeforeBeanDiscoveryImpl.fire(BeforeBeanDiscoveryImpl.java:46) at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:322) at org.jboss.weld.environment.se.Weld.initialize(Weld.java:85)
Does anybody know, what's happening here and how to solve this?
Thanks a lot for any clues
Hanspeter
Ok, I found the cause:
I did have some mix-ups with my context scopes in the be injected classes.
Now my Pojo is @ApplicationScoped (with the obligatory non-arg ctor) and it works as expected.