依赖注入在使用 Jersey 和 OpenWebBeans 的 Tomcat 7 上不起作用
Posted
技术标签:
【中文标题】依赖注入在使用 Jersey 和 OpenWebBeans 的 Tomcat 7 上不起作用【英文标题】:Dependency Injection won't work on Tomcat 7 using Jersey and OpenWebBeans 【发布时间】:2012-04-07 04:32:58 【问题描述】:我有点被我的问题困住了。我尝试使用 Jersey 运行 RESTful Web 服务,并将其与使用 Tomcat7 上的 OpenWebBeans 的一些依赖注入结合起来。 Jersey 部分本身似乎运行良好,但是当我创建 beans.xml 文件时,我得到了下面提到的错误......
所以我们开始:
我在 Eclipse 中使用 Maven 创建了项目:
文件->新建->其他->Maven项目->maven-archetype-webapp 并添加了 src/main/java 文件夹
文件树如下所示:
TJOWB |-部署描述符 |-Java 资源 |---src/main/资源 |-----META-INF |-------beans.xml |---src/main/java |-----a.b.c |-------Greeting.java |-------Hello.java |---图书馆 |-javascript 资源 |-部署资源 |-pom.xml |-src |-主要 |---java |---资源 |-----META-INF |-------beans.xml |---网络应用 |-----index.jsp |-----WEB-INF |-------beans.xml |-------web.xml |-目标
pom.xml 文件:
(由于我不知道,*** 中缺少项目定义,抱歉)
<modelVersion>4.0.0</modelVersion>
<groupId>a.b.c</groupId>
<artifactId>TJOWB</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>TJOWB Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.12</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.12</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-tomcat7</artifactId>
<version>1.1.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-impl</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-interceptor_1.1_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-web</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-ee-common</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jcdi_1.0_spec</artifactId>
<scope>provided</scope>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<scope>provided</scope>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-spi</artifactId>
<version>1.1.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-resource</artifactId>
<version>1.1.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
<finalName>TJOWB</finalName>
</build>
web.xml:
原型创建的 Web 应用程序
<listener>
<listener-class>org.apache.webbeans.web.tomcat.ContextLifecycleListener</listener-class>
</listener>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>a.b.c</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
添加到
Tomcat /lib:
geronimo-atinject_1.0_spec-1.0.jar geronimo-interceptor_1.1_spec-1.0.jar geronimo-interceptor_3.0_spech-1.0.jar geronimo-jcdi_1.0_spec-1.0.jar javassist_3.12.1.GA.jar openwebbeans-impl-1.1.3.jar openwebbeans-resource-1.1.3.jar openwebbeans-spi-1.1.3.jar openwebbeans-tomcat7-1.1.3.jar openwebbeans-web-1.1.3.jar scannotation-1.0.2.jar
在 Tomcat /conf/server.xml 中
Listener className="org.apache.webbeans.web.tomcat.ContextLifecycleListener" /
你好.java:
package a.b.c;
import javax.annotation.ManagedBean;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("inject")
public class Hello
@Inject
private Greeting mGreeting;
public Hello()
@PostConstruct
public void init()
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello()
if (mGreeting != null)
return mGreeting.greetUser();
else
return "Dependency Injection failed";
问候.java:
package a.b.c;
public class Greeting
public String greetUser()
return "Hello";
所以,现在是实际的错误消息:
如果 src/main/webapp/WEB-INF 中没有 beans.xml,则应用程序可以正常工作。至少它开始了,泽西岛起作用了;)
但是一旦我创建了 beans.xml((我必须这样做,我想)bean.xml 只包含我无法在此处显示的 beans 标签(因为我不知道如何),否则是 emtpy ) 我得到以下堆栈跟踪:
Tomcat7 启动:
Mrz 22, 2012 1:58:00 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\glassfish3\jdk7\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:/Program Files/Java/jre6/lib/i386;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS \System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\apache-maven-2.2.1-bin\apache-maven- 2.2.1\bin;C:\glassfish3\jdk7\bin;C:\Users\mvesper\Desktop\IndigoEE;;.
Mrz 22, 2012 1:58:00 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]Server/Service/Engine/Host/Context Setting property 'source' to 'org.eclipse.jst.j2ee.server:TJOWB' did not find a matching property.
Mrz 22, 2012 1:58:00 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Mrz 22, 2012 1:58:00 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Mrz 22, 2012 1:58:00 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 421 ms
Mrz 22, 2012 1:58:00 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Mrz 22, 2012 1:58:00 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.26
Mrz 22, 2012 1:58:01 PM org.apache.webbeans.web.lifecycle.WebContainerLifecycle startApplication
INFO: OpenWebBeans Container is starting...
Mrz 22, 2012 1:58:01 PM org.apache.webbeans.plugins.PluginLoader startUp
INFO: Adding OpenWebBeansPlugin : [TomcatWebPlugin]
Mrz 22, 2012 1:58:01 PM org.apache.webbeans.web.scanner.WebScannerService addWebBeansXmlLocation
INFO: added beans.xml marker: file:/C:/Users/mvesper/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpweb apps/TJOWB/WEB-INF/classes/META-INF/beans.xml
Mrz 22, 2012 1:58:01 PM org.apache.webbeans.web.scanner.WebScannerService addWebBeansXmlLocation
INFO: added beans.xml marker: jndi:/localhost/TJOWB/WEB-INF/beans.xml
Mrz 22, 2012 1:58:01 PM org.apache.webbeans.config.BeansDeployer validateInjectionPoints
INFO: All injection points were validated successfully.
Mrz 22, 2012 1:58:01 PM org.apache.webbeans.web.lifecycle.WebContainerLifecycle startApplication
INFO: OpenWebBeans Container has started, it took [247] ms.
Mrz 22, 2012 1:58:01 PM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
a.b.c
Mrz 22, 2012 1:58:01 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
class a.b.c.Hello
Mrz 22, 2012 1:58:01 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
Mrz 22, 2012 1:58:01 PM com.sun.jersey.server.impl.cdi.CDIComponentProviderFactoryInitializer initialize
INFO: CDI support is enabled
Mrz 22, 2012 1:58:01 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.12 02/15/2012 04:51 PM'
Mrz 22, 2012 1:58:02 PM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
java.lang.NoClassDefFoundError: javax/annotation/ManagedBean
at com.sun.jersey.server.impl.cdi.CDIComponentProviderFactory.getComponentProvider( tProviderFactory.java:116)
at com.sun.jersey.server.impl.component.IoCResourceFactory.getComponentProvider(IoCResourceFac tory.java:76)
at com.sun.jersey.server.impl.application.WebApplicationImpl.getResourceComponentProvider(WebA pplicationImpl.java:582)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiateResource(WebApplicationImpl.java:660)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiateResource(WebApplicationImpl.java:655)
at com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:124)
at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1308)
at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:171)
at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:777)
at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:773)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:773)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:768)
at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:607)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:208)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5015)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5302)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: javax.annotation.ManagedBean
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1701)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
... 33 more
Mrz 22, 2012 1:58:02 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /TJOWB threw load() exception
java.lang.ClassNotFoundException: javax.annotation.ManagedBean
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1701)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
at com.sun.jersey.server.impl.cdi.CDIComponentProviderFactory.getComponentProvider(CDIComponentProviderFactory.java:116)
at com.sun.jersey.server.impl.component.IoCResourceFactory.getComponentProvider(IoCResourceFactory.java:76)
at com.sun.jersey.server.impl.application.WebApplicationImpl.getResourceComponentProvider(WebApplicationImpl.java:582)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiateResource(WebApplicationImpl.java:660)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiateResource(WebApplicationImpl.java:655)
at com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:124)
at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1308)
at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:171)
at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:777)
at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:773)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:773)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:768)
at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:607)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:208)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5015)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5302)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Mrz 22, 2012 1:58:02 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Mrz 22, 2012 1:58:02 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Mrz 22, 2012 1:58:02 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1212 ms
当我尝试访问 localhost:8080/TJOWB/rest/inject:
Mrz 22, 2012 2:11:29 PM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
a.b.c
Mrz 22, 2012 2:11:29 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
class a.b.c.Hello
Mrz 22, 2012 2:11:29 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
Mrz 22, 2012 2:11:29 PM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
java.lang.RuntimeException: javax.naming.NameNotFoundException: Name CDIExtension is not bound in this Context
at com.sun.jersey.server.impl.cdi.CDIExtension.getInitializedExtension(CDIExtension.java:177)
at com.sun.jersey.server.impl.cdi.CDIComponentProviderFactory.<init> (CDIComponentProviderFactory.java:92)
at com.sun.jersey.server.impl.cdi.CDIComponentProviderFactoryInitializer.initialize(CDIComponentProviderFactoryInitializer.java:75)
at com.sun.jersey.spi.container.servlet.WebComponent.configure(WebComponent.java:574)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.configure(ServletContainer.java:311)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:606)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:208)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:857)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.naming.NameNotFoundException: Name CDIExtension is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:820)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
at com.sun.jersey.server.impl.cdi.CDIExtension.getInitializedExtension(CDIExtension.java:175)
... 26 more
Mrz 22, 2012 2:11:29 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet TestServlet
javax.naming.NameNotFoundException: Name CDIExtension is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:820)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
at com.sun.jersey.server.impl.cdi.CDIExtension.getInitializedExtension(CDIExtension.java:175)
at com.sun.jersey.server.impl.cdi.CDIComponentProviderFactory.<init>(CDIComponentProviderFactory.java:92)
at com.sun.jersey.server.impl.cdi.CDIComponentProviderFactoryInitializer.initialize(CDIComponentProviderFactoryInitializer.java:75)
at com.sun.jersey.spi.container.servlet.WebComponent.configure(WebComponent.java:574)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.configure(ServletContainer.java:311)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:606)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:208)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:857)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
所以,我想这就是它。
请原谅我的英语和格式。
提前致谢!
【问题讨论】:
你解决了吗?我遇到了同样的问题。 如果你在 github 上有一些示例应用程序,那么我会看看你的设置。 【参考方案1】:请从这里阅读我的帖子以查看第一个问题的解决方案: Attempting to use Jersey (JAX-RS) and Weld (CDI) in Tomcat 7. Getting noClassDefFoundError for javax.annotation.ManagedBean.
请确保为 tomcat 引导 CDI 的方式是正确的:这是一个非常有用的资源:@987654322@
尼库
【讨论】:
【参考方案2】:好的,我也遇到了同样的问题,解决方法很简单(虽然调试了半天)
只需使用 @ManagedBean
注释您的 Hello 类
【讨论】:
以上是关于依赖注入在使用 Jersey 和 OpenWebBeans 的 Tomcat 7 上不起作用的主要内容,如果未能解决你的问题,请参考以下文章
使用 jersey 测试框架时 Servlet 上下文注入失败
jersey 2.2 和 Spring Security 3 依赖项?