简体   繁体   English

"无法将 org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory 转换为 org.glassfish.jersey.internal.inject.InjectionManagerFactory"

[英]Cannot cast org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory to org.glassfish.jersey.internal.inject.InjectionManagerFactory

I am getting the following exception when using javax HTTP client.使用 javax HTTP 客户端时出现以下异常。 Any idea why this might be happening?知道为什么会发生这种情况吗?

java.lang.ClassCastException: Cannot cast org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory to org.glassfish.jersey.internal.inject.InjectionManagerFactory
    at java.lang.Class.cast(Class.java:3369)
    at org.glassfish.jersey.internal.ServiceFinder$LazyObjectIterator.hasNext(ServiceFinder.java:714)
    at org.glassfish.jersey.internal.inject.Injections.lookupService(Injections.java:112)
    at org.glassfish.jersey.internal.inject.Injections.lookupInjectionManagerFactory(Injections.java:97)
    at org.glassfish.jersey.internal.inject.Injections.createInjectionManager(Injections.java:68)
    at org.glassfish.jersey.client.ClientConfig$State.initRuntime(ClientConfig.java:432)
    at org.glassfish.jersey.internal.util.collection.Values$LazyValueImpl.get(Values.java:341)
    at org.glassfish.jersey.client.ClientConfig.getRuntime(ClientConfig.java:826)
    at org.glassfish.jersey.client.ClientRequest.getConfiguration(ClientRequest.java:285)
    at org.glassfish.jersey.client.JerseyInvocation.validateHttpMethodAndEntity(JerseyInvocation.java:143)
    at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:112)
    at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:108)
    at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:99)
    at org.glassfish.jersey.client.JerseyInvocation$AsyncInvoker.method(JerseyInvocation.java:706)
    at org.glassfish.jersey.client.JerseyInvocation$AsyncInvoker.get(JerseyInvocation.java:566)

It certainly is a classloader issue;这当然是一个类加载器问题; I have recently faced the same problem with Jersey 2.35.我最近在 Jersey 2.35 上遇到了同样的问题。 What In understand, Jersey internals in terms of dependency injection architecture has changed (Refer this post: wypieprz answer<\/a> ).据了解,Jersey 内部在依赖注入架构方面发生了变化(请参阅这篇文章: wypieprz answer<\/a> )。

The above occurs due to 'classloader shadowing' (if there is such a term).上述情况是由于“类加载器阴影”(如果有这样的术语)而发生的。 the contention is between the container class loader (in my case Tomcat JARClassLoader) and web-app class loader (WebbAppClassLoader of Tomcat).争用是在容器类加载器(在我的例子中是 Tomcat JARClassLoader)和 web-app 类加载器(Tomcat 的 WebbAppClassLoader)之间。

Since class loaded by different class loaders are not considered same.由于不同类加载器加载的类不被认为是相同的。 Therefore, in your case (and as was in mine), the 'Hk2InjectionManagerFactory' class and the 'InjectionManagerFactory' class was loaded by different class loaders and therefore the assignment fails with class cast exception.因此,在您的情况下(和我的情况一样),“Hk2InjectionManagerFactory”类和“InjectionManagerFactory”类是由不同的类加载器加载的,因此分配失败并出现类转换异常。

In my case, the problem was, I had, 'jersey-common' and 'jersey-client' on both web-app and Tomcat common loader (container class path).就我而言,问题是,我在 web-app 和 Tomcat 通用加载器(容器类路径)上都有“jersey-common”和“jersey-client”。 This caused the problem.这导致了问题。

The solution was to move all the Jersey related classes to WEB-INF\/lib and the library which depended upon jersey-client also to WEB-INF lib.解决方案是将所有与 Jersey 相关的类移动到 WEB-INF\/lib,并将依赖于 jersey-client 的库也移动到 WEB-INF lib。

In addition, also check your classpath (container class path), if there are any other older versions of jersey related jars.此外,还要检查你的类路径(容器类路径),是否还有其他旧版本的球衣相关 jar。

"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 注入上下文HttpServletRequest导致“接口org.glassfish.hk2.api.ProxyCtl在类加载器中不可见”(jersey 2.21,weblogic 12.1.3) - inject context HttpServletRequest cause “interface org.glassfish.hk2.api.ProxyCtl is not visible from class loader” (jersey 2.21, weblogic 12.1.3) java.lang.NoSuchMethodError: org.glassfish.hk2.api.ServiceLocatorFactory.creat - Jersey - java.lang.NoSuchMethodError: org.glassfish.hk2.api.ServiceLocatorFactory.creat - Jersey java.lang.NoClassDefFoundError: org/glassfish/jersey/internal/inject/Binder 启动 Tomcat 服务器时 - java.lang.NoClassDefFoundError: org/glassfish/jersey/internal/inject/Binder when started Tomcat Server 球衣测试+ HK2 +注入工厂服务 - Jersey Test + HK2 + Inject Factory service 让HK2和Jersey注入课程 - Getting hk2 and Jersey to inject classes NoClassDefFoundError:org / glassfish / jersey / process / internal / RequestExecutorFactory - NoClassDefFoundError: org/glassfish/jersey/process/internal/RequestExecutorFactory org.glassfish.jersey.internal.RuntimeDelegateImpl 未找到 - org.glassfish.jersey.internal.RuntimeDelegateImpl NOT FOUND Jersey 停止工作,找不到 InjectionManagerFactory - Jersey stopped working with InjectionManagerFactory not found 如何在jersey 2.0中使用hk2注入常量? - How do I inject constants with hk2 in jersey 2.0? 泽西岛:无法注入HttpServletRequest,出现hk2错误 - Jersey: can't inject HttpServletRequest, getting hk2 errors
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM