java.lang.AbstractMethodError: on Jersey Rest Webservice call after upgrading Weblogic to 12c (12.1.3.0.0)

java.lang.AbstractMethodError: on Jersey Rest Webservice call after upgrading Weblogic to 12c (12.1.3.0.0)

在我们将 Weblogic 升级到 Weblogic 12C - 12.1.3.0.0 后,使用 Jersey Client 2.15 调用 REST web 服务的应用程序的一部分停止工作。

我们得到的异常跟踪是:

java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
    at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)
    at org.glassfish.jersey.client.JerseyWebTarget.<init>(JerseyWebTarget.java:71)
    at org.glassfish.jersey.client.JerseyClient.target(JerseyClient.java:185)
    at org.glassfish.jersey.client.JerseyClient.target(JerseyClient.java:70)

我们确定这是 Jersey 和 Weblogic WS 库之间的 javax.ws.rs 不匹配。

依赖项

<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>2.15</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-common</artifactId>
    <version>2.15</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.0.1</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.4</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.connectors</groupId>
    <artifactId>jersey-apache-connector</artifactId>
    <version>2.15</version>
</dependency>

我们不再意识到使用上述堆栈跟踪跟踪我们的应用程序日志是一种误导。所以我们开始研究 Weblogic 日志。域日志实际上给出了完全不同的堆栈跟踪:

java.lang.NoSuchMethodError: org.glassfish.hk2.api.ServiceLocatorFactory.create(Ljava/lang/String;Lorg/glassfish/hk2/api/ServiceLocator;Lorg/glassfish/hk2/extension/ServiceLocatorGenerator;Lorg/glassfish/hk2/api/ServiceLocatorFactory$CreatePolicy;)Lorg/glassfish/hk2/api/ServiceLocator;
    at org.glassfish.jersey.internal.inject.Injections._createLocator(Injections.java:138)
    at org.glassfish.jersey.internal.inject.Injections.createLocator(Injections.java:109)
    at org.glassfish.jersey.internal.RuntimeDelegateImpl.<init>(RuntimeDelegateImpl.java:63)
    at 

因此,经过一番救火并尝试使用 weblogic.xml 和包覆盖后,问题得到了解决。以下是实际解决问题的最终包覆盖:

    <wls:package-name>com.sun.jersey.*</wls:package-name>
    <wls:package-name>org.glassfish.jersey.*</wls:package-name>
    <wls:package-name>org.glassfish.hk2.*</wls:package-name>
    <wls:package-name>org.jvnet.hk2.*</wls:package-name>
    <wls:package-name>jersey.repackaged.org.objectweb.asm.*</wls:package-name>
    <wls:package-name>org.objectweb.asm.*</wls:package-name>
    <wls:package-name>com.sun.ws.rs.ext.*</wls:package-name>
    <wls:package-name>javax.ws.rs.*</wls:package-name>