1 Reply Latest reply on Dec 2, 2011 11:03 AM by hpgisler

    Weld.SE: how to get Instances of bean containing @Produces methods?

    hpgisler

      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