在 Weblogic 12.1.3 上部署 Jersey 应用程序

Deploying a Jersey application on Weblogic 12.1.3

我在将 Jersey 应用程序部署到 Weblogic 12 时遇到困难,我花了很多时间来解决这个问题,但仍在苦苦挣扎。我遵循了各种网站(包括这个网站)上的各种建议,但我仍然遇到问题。我不知道我是否从根本上误解了一些基本的东西,所以我希望有人能帮助我。

这是我目前的情况:

我创建了一个新的 maven 项目。 这是我的 POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>uk.co.omnicomengineering</groupId>
<artifactId>jersey-weblogic</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>jersey-weblogic</name>

<build>
    <finalName>jersey-weblogic</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <inherited>true</inherited>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
        <version>2.19</version>
    </dependency>
    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs-api</artifactId>
        <version>2.0.1</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

我还像 https://docs.oracle.com/middleware/1213/wls/RESTF/use-jersey20-ri.htm#RESTF299 一样将 jax-rs 部署到 Weblogic,并将以下 weblogic.xml 添加到我的 WEB-INF 目录:

<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.7/weblogic-web-app.xsd">

<wls:library-ref>
   <wls:library-name>jax-rs</wls:library-name>
   <wls:specification-version>2.0</wls:specification-version>
   <wls:exact-match>false</wls:exact-match>
</wls:library-ref>

现在,当我尝试部署应用程序时,出现以下错误:

<06-Jul-2015 11:19:45 o'clock BST> <Error> <HTTP> <BEA-101216> <Servlet: "Jersey Web Application" failed to preload on startup in Web application: "jersey-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:123)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:329)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:339)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
Truncated. see log file for complete stacktrace
> 
<06-Jul-2015 11:19:45 o'clock BST> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID "10095322227139" for task "12". Error is: "weblogic.application.ModuleException: 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;"
weblogic.application.ModuleException: 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 weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
at weblogic.application.internal.flow.ModuleStateDriver.next(ModuleStateDriver.java:216)
at weblogic.application.internal.flow.ModuleStateDriver.next(ModuleStateDriver.java:211)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
Truncated. see log file for complete stacktrace
Caused By: 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:123)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:329)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:339)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
Truncated. see log file for complete stacktrace
> 
<06-Jul-2015 11:19:45 o'clock BST> <Error> <Deployer> <BEA-149202> <Encountered an exception while attempting to commit the 7 task for the application "_auto_generated_ear_".> 
<06-Jul-2015 11:19:45 o'clock BST> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating start task for application "_auto_generated_ear_".> 
<06-Jul-2015 11:19:45 o'clock BST> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
weblogic.application.ModuleException: 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 weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
at weblogic.application.internal.flow.ModuleStateDriver.next(ModuleStateDriver.java:216)
at weblogic.application.internal.flow.ModuleStateDriver.next(ModuleStateDriver.java:211)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
Truncated. see log file for complete stacktrace
Caused By: 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:123)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:329)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:339)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
Truncated. see log file for complete stacktrace

我不太确定哪里出了问题;我在 POM 中使用了错误的依赖项吗?

任何人都可以提供任何帮助,我将不胜感激,我花了很多时间与 Weblogic 和 Jersey 作斗争!

--编辑--

我已将以下内容添加到我的 weblogic.xml(在 http://www.widecodes.com/CxVkWWgPUj/using-jersey-2x-web-service-on-weblogic-1211.html 之后,这似乎是一个类似的问题):

<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.7/weblogic-web-app.xsd">

<library-ref>
   <library-name>jax-rs</library-name>
   <specification-version>2.0</specification-version>
   <exact-match>false</exact-match>
</library-ref>

<container-descriptor>
<prefer-application-packages>
    <package-name>com.sun.jersey.*</package-name>
    <package-name>org.glassfish.jersey.*</package-name>
    <package-name>org.glassfish.hk2.*</package-name>
    <package-name>org.jvnet.hk2.*</package-name>
    <package-name>jersey.repackaged.org.objectweb.asm.*</package-name>

    <package-name>com.sun.research.ws.wadl.*</package-name>
    <package-name>com.sun.ws.rs.ext.*</package-name>

    <package-name>org.codehaus.jackson.*</package-name>
    <package-name>com.fasterxml.jackson.*</package-name>

    <package-name>org.codehaus.jettison.*</package-name>

    <package-name>javax.ws.rs.*</package-name>

    <package-name>org.objectweb.asm.*</package-name>

    <package-name>antlr.*</package-name>
</prefer-application-packages>
</container-descriptor> 

现在,当我部署时出现以下错误:

<08-Jul-2015 14:16:25 o'clock BST> <Error> <HTTP> <BEA-101216> <Servlet: "Jersey Web Application" failed to preload on startup in Web application: "jersey-weblogic".
java.lang.NoSuchMethodError: org.glassfish.jersey.internal.util.PropertiesHelper.getValue(Ljava/util/Map;Ljavax/ws/rs/RuntimeType;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
at org.glassfish.jersey.moxy.json.MoxyJsonFeature.configure(MoxyJsonFeature.java:67)
at org.glassfish.jersey.model.internal.CommonConfig.configureFeatures(CommonConfig.java:714)
at org.glassfish.jersey.model.internal.CommonConfig.configureMetaProviders(CommonConfig.java:644)
at org.glassfish.jersey.server.ResourceConfig.configureMetaProviders(ResourceConfig.java:822)
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:452)
Truncated. see log file for complete stacktrace
> 
<08-Jul-2015 14:16:26 o'clock BST> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID "193463109842784" for task "12". Error is: "weblogic.application.ModuleException: java.lang.NoSuchMethodError: org.glassfish.jersey.internal.util.PropertiesHelper.getValue(Ljava/util/Map;Ljavax/ws/rs/RuntimeType;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;"
weblogic.application.ModuleException: java.lang.NoSuchMethodError: org.glassfish.jersey.internal.util.PropertiesHelper.getValue(Ljava/util/Map;Ljavax/ws/rs/RuntimeType;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
at weblogic.application.internal.flow.ModuleStateDriver.next(ModuleStateDriver.java:216)
at weblogic.application.internal.flow.ModuleStateDriver.next(ModuleStateDriver.java:211)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
Truncated. see log file for complete stacktrace
Caused By: java.lang.NoSuchMethodError: org.glassfish.jersey.internal.util.PropertiesHelper.getValue(Ljava/util/Map;Ljavax/ws/rs/RuntimeType;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
at org.glassfish.jersey.moxy.json.MoxyJsonFeature.configure(MoxyJsonFeature.java:67)
at org.glassfish.jersey.model.internal.CommonConfig.configureFeatures(CommonConfig.java:714)
at org.glassfish.jersey.model.internal.CommonConfig.configureMetaProviders(CommonConfig.java:644)
at org.glassfish.jersey.server.ResourceConfig.configureMetaProviders(ResourceConfig.java:822)
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:452)
Truncated. see log file for complete stacktrace
> 
<08-Jul-2015 14:16:26 o'clock BST> <Error> <Deployer> <BEA-149202> <Encountered an exception while attempting to commit the 7 task for the application "_auto_generated_ear_".> 
<08-Jul-2015 14:16:26 o'clock BST> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating start task for application "_auto_generated_ear_".> 
<08-Jul-2015 14:16:26 o'clock BST> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
weblogic.application.ModuleException: java.lang.NoSuchMethodError: org.glassfish.jersey.internal.util.PropertiesHelper.getValue(Ljava/util/Map;Ljavax/ws/rs/RuntimeType;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
at weblogic.application.internal.flow.ModuleStateDriver.next(ModuleStateDriver.java:216)
at weblogic.application.internal.flow.ModuleStateDriver.next(ModuleStateDriver.java:211)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
Truncated. see log file for complete stacktrace
Caused By: java.lang.NoSuchMethodError: org.glassfish.jersey.internal.util.PropertiesHelper.getValue(Ljava/util/Map;Ljavax/ws/rs/RuntimeType;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
at org.glassfish.jersey.moxy.json.MoxyJsonFeature.configure(MoxyJsonFeature.java:67)
at org.glassfish.jersey.model.internal.CommonConfig.configureFeatures(CommonConfig.java:714)
at org.glassfish.jersey.model.internal.CommonConfig.configureMetaProviders(CommonConfig.java:644)
at org.glassfish.jersey.server.ResourceConfig.configureMetaProviders(ResourceConfig.java:822)
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:452)
Truncated. see log file for complete stacktrace

由于您最初尝试将 jersey 部署为 WLS 中的共享库,我假设您没有随 EAR 文件一起提供 jersey jar 文件,或者至少这不是本意。

  1. 我怀疑最初的问题是您可能从可部署库中部署了旧版本的 jax-rs。您希望在部署中看到的是 jax-rs(2.0,2.5.1) - 规范 2.0,实施 2.5.1 - 作为共享库部署。

  2. 你不应该放入 weblogic.xml 除非你想要你指定的包 "must always be loaded from the application" (ref Oracle doc here) - 即 wls 会寻找提供的这些包从你的 EAR - 我怀疑这不是你想做的。如果您想提供自己的球衣文件版本,您只会这样做 - 通常比 WLS 提供的版本更新。

我建议您取消在 weblogic.xml 上所做的更改,重新部署 jax-rs 共享库,并确保您没有意外地将任何 jersey jar 文件包含在您的 EAR 中。我不是 maven 用户,所以我不确定 POM 文件中的内容是否会自动将这些依赖文件包含在 EAR 文件中。如果您想使用 Jersey 的 WLS 版本,则不需要这样做。

此外,不确定这是否会产生影响,但在我的 weblogic.xml 版本中,我包含了与共享库相匹配的实现版本。

<wls:library-ref>  
    <wls:library-name>jax-rs</wls:library-name>  
    <wls:specification-version>2.0</wls:specification-version>
    <wls:implementation-version>2.5.1</wls:implementation-version>  
    <wls:exact-match>false</wls:exact-match>
</wls:library-ref>

祝你好运。这些部署问题可能会非常棘手。

您可能已经知道,在将 JAX-RS 应用程序部署到 Weblogic 之前,您必须在服务器上安装 jax-rs 共享库。它位于 $WLHOME/common/deployable-libraries/jax-rs-2.0.war

之后,您的 ear/war 应用程序中不应有任何球衣罐。您只需引用 weblogic.xml 中的 jax-rs 库,最好使用其实现版本。这个 <prefer-application-packages> 部分应该在 jax-rs 库 war 中的 weblogic.xml 中定义,而不是在你的 weblogic.xml.

中定义

如果您想使用更新版本的 jax-rs 库,请检查 this answer