1 2 Previous Next 19 Replies Latest reply on Apr 12, 2014 9:57 PM by Jun Wang

    Weld and Jersey web framework problem.

    kchen007 Apprentice

      I am using JBOSS 7.1 Final and has war application that is based on Jersey. When I tried to use CDI, I got the following exception.  Do I miss something? I only add the listener in the web.xml and create the bean.xml as stated in the weld documentation. Thanks.

       

      Caused by: org.jboss.weld.exceptions.IllegalArgumentException: WELD-001001 Cannot pass null expressionFactory

              at org.jboss.weld.el.WeldExpressionFactory.<init>(WeldExpressionFactory.java:38) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.jboss.weld.manager.BeanManagerImpl.wrapExpressionFactory(BeanManagerImpl.java:995) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

              at org.jboss.as.weld.webtier.jsf.WeldApplication.getExpressionFactory(WeldApplication.java:91) [jboss-as-weld-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.weld.environment.servlet.jsf.WeldApplication.init(WeldApplication.java:79) [weld-servlet-core.jar:20121012-1000]

              at org.jboss.weld.environment.servlet.jsf.WeldApplication.delegate(WeldApplication.java:87) [weld-servlet-core.jar:20121012-1000]

              at org.jboss.weld.environment.servlet.jsf.ForwardingApplication.addELContextListener(ForwardingApplication.java:83) [weld-servlet-core.jar:20121012-1000

      ]

              at org.jboss.weld.environment.servlet.jsf.WeldApplication.<init>(WeldApplication.java:71) [weld-servlet-core.jar:20121012-1000]

              at org.jboss.weld.environment.servlet.jsf.WeldApplicationFactory.getApplication(WeldApplicationFactory.java:47) [weld-servlet-core.jar:20121012-1000]

              at com.sun.faces.application.InjectionApplicationFactory.getApplication(InjectionApplicationFactory.java:91) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at com.sun.faces.config.processor.AbstractConfigProcessor.getApplication(AbstractConfigProcessor.java:130) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at com.sun.faces.config.processor.ApplicationConfigProcessor.process(ApplicationConfigProcessor.java:255) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at com.sun.faces.config.processor.AbstractConfigProcessor.invokeNext(AbstractConfigProcessor.java:114) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at com.sun.faces.config.processor.LifecycleConfigProcessor.process(LifecycleConfigProcessor.java:116) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at com.sun.faces.config.processor.AbstractConfigProcessor.invokeNext(AbstractConfigProcessor.java:114) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at com.sun.faces.config.processor.FactoryConfigProcessor.process(FactoryConfigProcessor.java:222) [jsf-impl-2.1.7-jbossorg-2.jar:]

              at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:361) [jsf-impl-2.1.7-jbossorg-2.jar:]

        • 1. Re: Weld and Jersey web container problem.
          Marko Lukša Apprentice

          Do you have weld jars inside the war? If so, remove them.

          • 2. Re: Weld and Jersey web container problem.
            kchen007 Apprentice

            Thanks Marko.

             

            I do have weld-servlet.jar in the war file, If I remove it from the war file, I will get the following class not found exception, and the injected object is null.  Where shall I put the weld-servlet.jar?

             

            10:31:05,682 INFO  [org.jboss.weld.deployer] (MSC service thread 1-15) JBAS016002: Processing weld deployment dsdataserver.war
            10:31:05,698 WARN  [org.jboss.as.ee] (MSC service thread 1-5) JBAS011006: Not installing optional component org.jboss.weld.environment.servlet.Listener due to e
            xception: java.lang.ClassNotFoundException: org.jboss.weld.environment.servlet.Listener from [Module "deployment.dsdataserver.war:main" from Service Module Load
            er]
                    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) [jboss-modules.jar:1.1.1.GA]
                    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) [jboss-modules.jar:1.1.1.GA]
                    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) [jboss-modules.jar:1.1.1.GA]
                    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423) [jboss-modules.jar:1.1.1.GA]
                    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) [jboss-modules.jar:1.1.1.GA]
                    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) [jboss-modules.jar:1.1.1.GA]
                    at java.lang.Class.forName0(Native Method) [rt.jar:1.6.0_37]
                    at java.lang.Class.forName(Class.java:247) [rt.jar:1.6.0_37]
                    at org.jboss.as.server.deployment.reflect.DeploymentClassIndex.classIndex(DeploymentClassIndex.java:54) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
                    at org.jboss.as.ee.component.deployers.EEModuleConfigurationProcessor.deploy(EEModuleConfigurationProcessor.java:79)
                    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
                    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_37]
                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_37]
                    at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_37]

            • 3. Re: Weld and Jersey web container problem.
              Marko Lukša Apprentice

              You can remove the reference to org.jboss.weld.environment.servlet.Listener from the web.xml. When running a CDI application inside JBossAS, you don't need weld-servlet and also don't need to add anything to web.xml. The application server automatically adds everything you need - all you need to do is add a beans.xml, so the server enables CDI for your app.

              • 4. Re: Weld and Jersey web container problem.
                kchen007 Apprentice

                If I remove the listener from web.xml, the jboss will start without problem, but the injected object is always null.

                • 5. Re: Weld and Jersey web container problem.
                  Marko Lukša Apprentice

                  And you are sure you have a beans.xml file in the correct place? What are you trying to inject into?

                  • 6. Re: Weld and Jersey web container problem.
                    kchen007 Apprentice

                    Yes, the beans.xml is under my

                     

                    war file's WEB-INF directory, the content is:

                         <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

                         http://java.sun.com/xml/ns/javaee/beans_1_0.xsdhttp://java.sun.com/xml/ns/javaee/beans_1_0.xsd">

                         </beans>

                     

                    Also, In JBOSS log, I see the following message:

                    15:35:24,538 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) JBAS016008: Starting weld service for deployment dsdataserver.war

                     

                    Here is code that I defined the Qualifier

                        

                    @Qualifier

                    @Retention

                    (RUNTIME)

                     

                     

                     

                    @Target

                     

                     

                    ({ TYPE, METHOD, PARAMETER, FIELD })

                    public

                     

                    @interface CoreServiceProducer{}

                     

                    In the bean, here is the provider

                     

                    @Produces

                     

                    @CoreServiceProducer

                     

                    public

                    ODataProducer getProducer() {.......}

                     

                    Here is the injection

                     

                    @Inject

                     

                     

                    @CoreServiceProducer

                    ODataProducer coreServiceProducer;

                     

                     

                    but the coreServiceProducer is always null.

                     

                    Thanks

                    Kevin

                     

                    • 7. Re: Weld and Jersey web container problem.
                      Marko Lukša Apprentice

                      How do you obtain the object that contains the injection point? Is it a servlet/filter or some other managed object? You aren't by any chance simply creating it with new Whatever()?

                      • 8. Re: Weld and Jersey web container problem.
                        kchen007 Apprentice

                        The class that contain the @Inject object is a request resource, DsdsCoreServiceBaseRequestResource(), I pass it to Jersey and when url pattern matched, Jersey will call it.

                         

                        • 9. Re: Weld and Jersey web container problem.
                          Martin Kouba Master

                          Looks like some Jersey-CDI integration problem (Jersey is not able to lookup BeanManager and thus JAX-RS CDI support is disabled). Do you have com.sun.jersey.server.impl.cdi.CDIComponentProviderFactoryInitializer in your classpath? Also if your example worked on Tomcat, a  workaround was probably used - changing the JNDI name Jersey is using to lookup BM to java:comp/env/BeanManager and this would break the app on a regular EE container (http://www.innoq.com/blog/me/blog/2012/02/27/jersey-cdi-and-tomcat/).


                          • 10. Re: Weld and Jersey web container problem.
                            kchen007 Apprentice

                            Thanks Martin. I upgrade my jersey to the latest version 1.17, and now I got the following exception,

                             

                            java.lang.UnsupportedOperationException: JBAS011859: Naming context is read-only
                                    at org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:126)
                                    at org.jboss.as.naming.WritableServiceBasedNamingStore.createSubcontext(WritableServiceBasedNamingStore.java:116)
                                    at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:338)
                                    at org.jboss.as.naming.InitialContext.createSubcontext(InitialContext.java:229)
                                    at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:346)
                                    at javax.naming.InitialContext.createSubcontext(InitialContext.java:464)
                                    at com.sun.jersey.server.impl.cdi.CDIExtension$1.stepInto(CDIExtension.java:280)
                                    at com.sun.jersey.server.impl.cdi.CDIExtension.diveIntoJNDIContext(CDIExtension.java:267)
                                    at com.sun.jersey.server.impl.cdi.CDIExtension.createJerseyConfigJNDIContext(CDIExtension.java:273)
                                    at com.sun.jersey.server.impl.cdi.CDIExtension.initialize(CDIExtension.java:192)
                                    at com.sun.jersey.server.impl.cdi.CDIExtension.beforeBeanDiscovery(CDIExtension.java:297)
                                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                    at java.lang.reflect.Method.invoke(Method.java:597)
                                    at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:264)
                                    at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52)
                                    at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137)
                                    at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:260)
                                    at org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:170)
                                    at org.jboss.weld.introspector.ForwardingWeldMethod.invokeOnInstance(ForwardingWeldMethod.java:51)
                                    at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:154)
                                    at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:241)
                                    at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:229)
                                    at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:207)
                                    at org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:75)
                                    at org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:46)
                                    at org.jboss.weld.bootstrap.events.BeforeBeanDiscoveryImpl.fire(BeforeBeanDiscoveryImpl.java:46)
                                    at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:322)
                                    at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:81)
                                    at org.jboss.as.weld.services.WeldService.start(WeldService.java:76)

                             

                            • 11. Re: Weld and Jersey web container problem.
                              Martin Kouba Master

                              Hm, looks like some JNDI binding problem... Actually, I'd try to remove all Jersey stuff (libraries and non-portable code) and rely on AS7 default JAX-RS implementation - RESTEasy. Jersery is obviously not tested on JBoss AS7 whereas RESTEasy is AS7 module.

                              • 12. Re: Weld and Jersey web container problem.
                                Ales Justin Master

                                This is actually fixed in AS7 upstream.

                                 

                                But as Martin suggest, it's better to use container' JAX-RS bits.

                                • 13. Re: Weld and Jersey web container problem.
                                  kchen007 Apprentice

                                  Martin/Ales:

                                  Thanks for information. Will the fix be in 7.1.2 final release? Since I cannot change the usage of Jersey.

                                  • 14. Re: Weld and Jersey web framework problem.
                                    Jun Wang Newbie

                                    Just tested in EAP 6.1.0 Beta and the issue still persist when trying to load jersey with beans.xml in place.

                                     

                                    01:23:37,814 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service jboss.deployment.unit."stock-ear-1.0-SNAPSHOT.ear".WeldStartSer

                                    vice: org.jboss.msc.service.StartException in service jboss.deployment.unit."stock-ear-1.0-SNAPSHOT.ear".WeldStartService: Failed to start service

                                            at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.4.GA.jar:1.0.4.GA]

                                            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_35]

                                            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_35]

                                            at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_35]

                                    Caused by: org.jboss.weld.exceptions.DefinitionException: Exception List with 1 exceptions:

                                    Exception 0 :

                                    java.lang.UnsupportedOperationException: JBAS011859: Naming context is read-only

                                            at org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:144)

                                            at org.jboss.as.naming.WritableServiceBasedNamingStore.createSubcontext(WritableServiceBasedNamingStore.java:134)

                                            at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:385)

                                            at org.jboss.as.naming.InitialContext.createSubcontext(InitialContext.java:183)

                                            at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:393)

                                            at javax.naming.InitialContext.createSubcontext(InitialContext.java:464)

                                            at com.sun.jersey.server.impl.cdi.CDIExtension$1.stepInto(CDIExtension.java:280)

                                            at com.sun.jersey.server.impl.cdi.CDIExtension.diveIntoJNDIContext(CDIExtension.java:267)

                                            at com.sun.jersey.server.impl.cdi.CDIExtension.createJerseyConfigJNDIContext(CDIExtension.java:273)

                                            at com.sun.jersey.server.impl.cdi.CDIExtension.initialize(CDIExtension.java:192)

                                            at com.sun.jersey.server.impl.cdi.CDIExtension.beforeBeanDiscovery(CDIExtension.java:297)

                                            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                                            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                                            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                                            at java.lang.reflect.Method.invoke(Method.java:597)

                                            at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:267)

                                            at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52)

                                            at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137)

                                            at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:263)

                                            at org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:170)

                                            at org.jboss.weld.introspector.ForwardingWeldMethod.invokeOnInstance(ForwardingWeldMethod.java:51)

                                            at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:154)

                                            at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:245)

                                            at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:233)

                                            at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:213)

                                            at org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:75)

                                            at org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:46)

                                            at org.jboss.weld.bootstrap.events.BeforeBeanDiscoveryImpl.fire(BeforeBeanDiscoveryImpl.java:46)

                                            at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:335)

                                            at org.jboss.as.weld.WeldStartService.start(WeldStartService.java:62)

                                            at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)

                                            at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)

                                            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

                                            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

                                            at java.lang.Thread.run(Thread.java:662)

                                     

                                     

                                            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:335)

                                            at org.jboss.as.weld.WeldStartService.start(WeldStartService.java:62)

                                            at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.4.GA.jar:1.0.4.GA]

                                            at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.4.GA.jar:1.0.4.GA]

                                            ... 3 more

                                    1 2 Previous Next