我尝试使用RESTEasy 3.0.6在Tomcat 7.0上部署Web应用程序以获得RESTful服务支持。但是,当我尝试部署应用程序时,我得到以下异常:
2014-04-09 11:25:27 DEBUG CdiInjectorFactory:68 - Doing a lookup for BeanManager in java:comp/BeanManager
2014-04-09 11:25:27 DEBUG CdiInjectorFactory:68 - Unable to obtain BeanManager from java:comp/BeanManager
2014-04-09 11:25:27 DEBUG CdiInjectorFactory:68 - Doing a lookup for BeanManager in java:app/BeanManager
2014-04-09 11:25:27 DEBUG CdiInjectorFactory:68 - Unable to obtain BeanManager from java:app/BeanManager
2014-04-09 11:25:27 DEBUG CdiInjectorFactory:75 - Not able to access CDI Object, class not found.
java.lang.ClassNotFoundException: javax.enterprise.inject.spi.CDI
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at org.jboss.resteasy.cdi.CdiInjectorFactory.lookupBeanManagerCDIUtil(CdiInjectorFactory.java:201)
at org.jboss.resteasy.cdi.CdiInjectorFactory.lookupBeanManager(CdiInjectorFactory.java:167)
at org.jboss.resteasy.cdi.CdiInjectorFactory.<init>(CdiInjectorFactory.java:42)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:374)
at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:148)
at org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap.contextInitialized(ResteasyBootstrap.java:28)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Apr 09, 2014 11:25:27 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
java.lang.RuntimeException: Unable to instantiate InjectorFactory implementation.
at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:156)
at org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap.contextInitialized(ResteasyBootstrap.java:28)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.RuntimeException: Unable to lookup BeanManager.
at org.jboss.resteasy.cdi.CdiInjectorFactory.lookupBeanManager(CdiInjectorFactory.java:174)
at org.jboss.resteasy.cdi.CdiInjectorFactory.<init>(CdiInjectorFactory.java:42)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:374)
at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:148)
... 10 more
关于如何将RESTEasy-CDI合并到我的Maven构建中,我跟着the instructions,我看到WAR正在构建正确。但是,我在部署时仍然会看到异常。
我的web.xml
文件的相关部分如下所示:
<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
</listener-class>
</listener>
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<filter>
<filter-name>ConversationPropagationFilter</filter-name>
<filter-class>org.jboss.weld.servlet.ConversationPropagationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ConversationPropagationFilter</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
<resource-env-ref>
<description>Object factory for the CDI Bean Manager</description>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.myapp.web.rest.JaxRsActivator</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
知道可能导致此问题的原因或如何解决此错误?在这一点上,它基本上是一个显示阻止。
答案 0 :(得分:1)
发现了这个问题。它只是一个servlet监听器排序问题。我在初始化CDI之前初始化了RESTEasy。