Jersey stopped working with InjectionManagerFactory not found

匿名 (未验证) 提交于 2019-12-03 01:27:01

问题:

I am receiving below error while running my jersey API in tomcat 8.5.11 which is causing my API to stop -:

HTTP Status 500 - Servlet.init() for servlet Jersey REST Service threw exception

type Exception report

message Servlet.init() for servlet Jersey REST Service threw exception

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet.init() for servlet Jersey REST Service threw exception org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783) org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1434) org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745)

root cause

java.lang.IllegalStateException: InjectionManagerFactory not found. org.glassfish.jersey.internal.inject.Injections.lookupInjectionManagerFactory(Injections.java:97) org.glassfish.jersey.internal.inject.Injections.createInjectionManager(Injections.java:89) org.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:282) org.glassfish.jersey.servlet.WebComponent.(WebComponent.java:335) org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:178) org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:370) javax.servlet.GenericServlet.init(GenericServlet.java:158) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783) org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1434) org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745)

The application is build with the following dependencies with gradle:

dependencies {     compile (         // REST         "org.glassfish.jersey.containers:jersey-container-servlet:2.+",         "javax.servlet:javax.servlet-api:4.+",         // REST Token         "org.bitbucket.b_c:jose4j:0.+",         // MongoDB         "org.hibernate.ogm:hibernate-ogm-bom:5.+",         "org.hibernate.ogm:hibernate-ogm-infinispan:5.+",         "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.+",         "org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.+",         "org.jboss.narayana.jta:narayana-jta:5.+",         "org.jboss:jboss-transaction-spi:7.+",         "log4j:log4j:1.+",         "org.hibernate.ogm:hibernate-ogm-mongodb:5.+",         "org.bouncycastle:bcprov-jdk15on:1.+"     ) }

This downloads jersey-common-2.26-b04.jar which contains the missing class under /org/glassfish/jersey/internal/inject/InjectionManagerFactory. The jar file is deployed into the tomcat folder under WEB-INF/lib

What can be wrong here? The gradle script worked the last few month with the same tomcat version.

回答1:

I have the same problem, after downgrading to the version deployed in march (2.26-b03) everything is back to normal, hope it helps



回答2:

Add this dependency:

org.glassfish.jersey.injectjersey-hk2

cf. https://stackoverflow.com/a/44536542/1070215



回答3:

Jersey 2.26 and newer are not backward compatible with older versions. The reason behind that has been stated in the release notes:

Unfortunately, there was a need to make backwards incompatible changes in 2.26. Concretely jersey-proprietary reactive client API is completely gone and cannot be supported any longer - it conflicts with what was introduced in JAX-RS 2.1 (that's the price for Jersey being "spec playground..").

Another bigger change in Jersey code is attempt to make Jersey core independent of any specific injection framework. As you might now, Jersey 2.x is (was!) pretty tightly dependent on HK2, which sometimes causes issues (esp. when running on other injection containers. Jersey now defines it's own injection facade, which, when implemented properly, replaces all internal Jersey injection.


As for now one should use the following dependencies:

Maven

org.glassfish.jersey.corejersey-common2.26org.glassfish.jersey.injectjersey-hk22.26

Gradle

compile 'org.glassfish.jersey.core:jersey-common:2.26' compile 'org.glassfish.jersey.inject:jersey-hk2:2.26'


回答4:

Downgrade the jersey version in pom.xml change the tag 2.26-b04 to 2.26-b03



回答5:

Choose which DI to inject stuff into Jersey:

Spring 4:

org.glassfish.jersey.extjersey-spring4

Spring 3:

org.glassfish.jersey.extjersey-spring3

HK2:

org.glassfish.jersey.injectjersey-hk2


回答6:

I have the same problem. I added the latest jersey-hk2 dependency and it works like a charm.

    org.glassfish.jersey.injectjersey-hk2


回答7:

As far as I can see dependencies have changed between 2.26-b03 and 2.26-b04 (HK2 was moved to from compile to testCompile)... there might be some change in the jersey dependencies that has not been completed yet (or which lead to a bug).

However, right now the simple solution is to stick to an older version :-)



回答8:

Yes, it's from the latest release from friday 19th may. I just changed my version in the Maven to an older one, and it's works perfect again.



回答9:

Here is the new dependency (August 2017)

     org.glassfish.jersey.corejersey-common2.0-m03


回答10:

I had the same issue with jersey version 2.26. I used the older version(v.2.16) and now its working fine.



回答11:

The only way I could solve it was via:

org.glassfish.jersey.core jersey-server ${jersey-2-version}

org.glassfish.jersey.containersjersey-container-servlet${jersey-2-version}org.glassfish.jersey.injectjersey-hk2${jersey-2-version}org.glassfish.jersey.corejersey-common${jersey-2-version}org.glassfish.jersey.containersjersey-container-servlet-core${jersey-2-version}

So, only if I added jersey-container-servlet and jersey-hk2 would it run without errors



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!