4 Replies Latest reply on Jan 2, 2015 3:56 AM by Jozef Hartinger

    Unable to obtain non-contextual instance

    Emily Jiang Newbie

      We are trying to obtain non-contextual instance as per CDI 1.2 section 11.3.4:

       

      Unmanaged<Foo> unmanagedFoo = new Unmanaged<Foo>(Foo.class);

      UnmanagedInstance<Foo> fooInstance = unmanagedFoo.newInstance();

      Foo foo = fooInstance.produce().inject().postConstruct().get();

       

      I got the following exception on running the above code:

      com.google.common.cache.LocalCache$Segment.get:2,263'

      com.google.common.util.concurrent.UncheckedExecutionException: org.jboss.weld.exceptions.IllegalStateException: WELD-001328: Unable to identify the correct BeanManager. The calling class javax.enterprise.inject.spi.Unmanaged is not placed in bean archive

      at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2263)

      at com.google.common.cache.LocalCache.get(LocalCache.java:4000)

      at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4004)

      at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4874)

      at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4880)

      at org.jboss.weld.SimpleCDI.getBeanManager(SimpleCDI.java:105)

      at org.jboss.weld.SimpleCDI.getBeanManager(SimpleCDI.java:38)

      at javax.enterprise.inject.spi.Unmanaged.<init>(Unmanaged.java:47)

      at cdi12.noncontextual.test.Servlet.doGet(Servlet.java:25)

      at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)

       

      Basically, Weld is trying to find bean manager for the class javax.enterprise.inject.spi.Unmanaged but cannot find it. Any ideas why?