Trying Jersey (JAX-RS) and Weld (CDI) in Tomcat 7. Getting noClassDefFoundError for javax.annotation.ManagedBean

I'm trying to get Weld to work with Jersey on Tomcat 7.0.34 but seems to be running into this issue. The actual exception is

java.lang.NoClassDefFoundError: javax/annotation/ManagedBean

      

but I am not annotating anything with @ManagedBean annotation, so I assume Weld is implicitly doing this. Should this annotation be provided by Weld, or am I missing some other dependency?

My pom.xml file contains:

<dependency>
    <!-- CDI implementation -->
    <groupId>org.jboss.weld.servlet</groupId>
    <artifactId>weld-servlet</artifactId>
    <version>${weld.version}</version>
</dependency>

      

Am I missing something, or is there a much bigger problem trying to use Weld and Jersey?


catalina.out when deploying my web app:

...
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'

      

catalina.out when making an HTTP request to a servlet using @Inject annotation

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'

      

The servlet responded to the request with an HTTP HTTP status code. Root Cause Stack Trace:

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)

      

Oddly enough, the stack trace doesn't show up in the catalina.out file, instead the log file shows what looks like an application redistribution!

0


source to share


3 answers


I had exactly the same problem and solved it by dumping the current jersey version which is 1.16 and using the older version which is 1.8. After using an older version, I no longer have this error.



0


source


I had the same problem as soon as I overloaded the ServletContainer as stated in: Weld + Jersey + Tomcat?



To be able to run it, I annotated my jersey service class with @RequestScoped and then injected.

0


source


just take a look inside the jersey jar (I am using jersey 1.14) especially in the pom file. You will see that it expects some of the provided dependencies, and one of them is javax.ejb 3.1:

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.ejb</artifactId>
    <version>3.1</version>
    <scope>provided</scope>
</dependency>

      

This jar contains the required class: javax.annotation.ManagedBean. If you import any other jar containing this class will not work. This is due to the fact that there was a jersey-jersey in the kit, but that's another story.

Just add this dependency inside your pom and everything will work fine.

Nick

0


source







All Articles