我试图让 Weld 在 Tomcat 7.0.34 上与 Jersey 一起工作,但似乎遇到了这个问题。实际的例外是
java.lang.NoClassDefFoundError: javax/annotation/ManagedBean
但是我没有用@ManagedBean 注释明确地注释任何东西,所以我猜Weld 隐含地这样做了。Weld 是否应该提供此注释,或者我是否缺少其他一些依赖项?
我的 pom.xml 文件包含:
<dependency>
<!-- CDI implementation -->
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>${weld.version}</version>
</dependency>
我是否遗漏了什么,或者尝试使用 Weld 和 Jersey 是否存在更大的问题?
catalina.out 部署我的网络应用程序时:
...
Jan 03, 2013 2:21:21 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /usr/local/Cellar/tomcat/7.0.34/libexec/webapps/tracker.war
Jan 03, 2013 2:21:22 AM org.jboss.weld.bootstrap.WeldBootstrap <clinit>
INFO: WELD-000900 1.1.10 (Final)
Jan 03, 2013 2:21:22 AM org.jboss.weld.bootstrap.WeldBootstrap startContainer
INFO: WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
Jan 03, 2013 2:21:22 AM org.jboss.weld.environment.tomcat7.Tomcat7Container initialize
INFO: Tomcat 7 detected, CDI injection will be available in Servlets and Filters. Injection into Listeners is not supported
Jan 03, 2013 2:21:22 AM org.jboss.weld.interceptor.util.InterceptionTypeRegistry <clinit>
WARNING: Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled
Jan 03, 2013 2:21:22 AM org.jboss.weld.interceptor.util.InterceptionTypeRegistry <clinit>
WARNING: Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled
Jan 03, 2013 2:21:22 AM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
...
Jan 03, 2013 2:21:22 AM com.sun.jersey.server.impl.cdi.CDIComponentProviderFactoryInitializer initialize
INFO: CDI support is enabled
Jan 03, 2013 2:21:22 AM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.16 11/28/2012 02:09 PM'
使用 @Inject 注释向 servlet 发出 HTTP 请求时的 catalina.out
Jan 03, 2013 2:23:12 AM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
substrate.tracker.api
Jan 03, 2013 2:23:12 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
class substrate.tracker.api.ProjectsResource
class substrate.tracker.api.UsersResource
class substrate.tracker.api.IssuesResource
class substrate.tracker.api.PingResource
Jan 03, 2013 2:23:12 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Provider classes found:
class substrate.tracker.api.exception.ParameterExceptionMapper
Jan 03, 2013 2:23:12 AM com.sun.jersey.server.impl.cdi.CDIComponentProviderFactoryInitializer initialize
INFO: CDI support is enabled
Jan 03, 2013 2:23:12 AM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.16 11/28/2012 02:09 PM'
servlet 使用 500 HTTP 状态代码响应请求。根本原因堆栈跟踪:
java.lang.NoClassDefFoundError: javax/annotation/ManagedBean
com.sun.jersey.server.impl.cdi.CDIComponentProviderFactory.getComponentProvider(CDIComponentProviderFactory.java:116)
com.sun.jersey.server.impl.cdi.CDIComponentProviderFactory.getComponentProvider(CDIComponentProviderFactory.java:103)
com.sun.jersey.core.spi.component.ioc.IoCProviderFactory._getComponentProvider(IoCProviderFactory.java:89)
com.sun.jersey.core.spi.component.ProviderFactory.getComponentProvider(ProviderFactory.java:153)
com.sun.jersey.core.spi.component.ProviderServices.getComponent(ProviderServices.java:251)
com.sun.jersey.core.spi.component.ProviderServices.getProviders(ProviderServices.java:148)
com.sun.jersey.server.impl.application.ExceptionMapperFactory.init(ExceptionMapperFactory.java:74)
com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1307)
com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:168)
com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:774)
com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:770)
com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:770)
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:765)
com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:489)
com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:319)
com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
java.lang.Thread.run(Thread.java:722)
奇怪的是,堆栈跟踪没有显示在 catalina.out 中,相反,日志文件显示了正在重新部署的应用程序的样子!