在Weblogic 12.1.3上部署Jersey应用程序

时间:2015-07-06 10:23:44

标签: java rest maven jersey-2.0 weblogic12c

我很难将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$3.next(ModuleStateDriver.java:216)
at weblogic.application.internal.flow.ModuleStateDriver$3.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$3.next(ModuleStateDriver.java:216)
at weblogic.application.internal.flow.ModuleStateDriver$3.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和泽西作战!

- 编辑 -

我已将以下内容添加到我的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$3.next(ModuleStateDriver.java:216)
at weblogic.application.internal.flow.ModuleStateDriver$3.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$3.next(ModuleStateDriver.java:216)
at weblogic.application.internal.flow.ModuleStateDriver$3.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

2 个答案:

答案 0 :(得分:3)

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

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

  2. 你不应该放入weblogic.xml,除非你希望你指定的包“必须始终从应用程序加载”(ref Oracle doc here) - 即wls会查找你提供的这些包EAR - 我怀疑这不是你想做的。如果您想提供自己版本的球衣文件,通常会提供比WLS提供的版本更新的版本。

  3. 我建议你退出你在weblogic.xml上所做的更改,重新部署jax-rs共享库,并确保你没有意外地在你的EAR中包含任何jersey jar文件。我不是maven用户,因此我不确定您在POM文件中拥有的内容会自动将这些相关文件包含在您的EAR文件中。如果你想使用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>
    
    祝你好运。这些部署问题可能令人抓狂。

答案 1 :(得分:1)

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

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

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