0

我使用“jersey”原型在eclipse中开发了一个非常小的restful Web服务。我也成功地在tomcat中部署了它。但是,我无法在 weblogic 12c 中部署它。这是我到目前为止所尝试的:

  1. 正如我在其中一篇文章中看到的那样,创建了一个包含球衣库的共享库。这是我的 pom.xml,它生成包含所需清单文件的共享库:

块引用

    <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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>jersey-shared-lib</groupId>
  <artifactId>jersey-shared-lib</artifactId>
  <version>2.21</version>

  <packaging>war</packaging>

  <dependencies>

    <dependency>
      <groupId>org.glassfish.jersey.core</groupId>
      <artifactId>jersey-server</artifactId>
      <version>${project.version}</version>
    </dependency>

    <dependency>
      <groupId>org.glassfish.jersey.core</groupId>
      <artifactId>jersey-client</artifactId>
      <version>${project.version}</version>
    </dependency>
     <dependency>
      <groupId>org.glassfish.jersey.media</groupId>
      <artifactId>jersey-media-moxy</artifactId>
      <version>${project.version}</version>
    </dependency>

    <dependency>
      <groupId>org.glassfish.jersey.containers</groupId>
      <artifactId>jersey-container-servlet-core</artifactId>
      <version>${project.version}</version>
    </dependency>
        <dependency>
      <groupId>org.glassfish.jersey.media</groupId>
      <artifactId>jersey-media-json-jackson</artifactId>
      <version>${project.version}</version>
    </dependency>
        <dependency>
      <groupId>org.glassfish.jersey.media</groupId>
      <artifactId>jersey-media-json-jettison</artifactId>
      <version>${project.version}</version>
    </dependency>
        <dependency>
      <groupId>org.glassfish.jersey.media</groupId>
      <artifactId>jersey-media-multipart</artifactId>
      <version>${project.version}</version>
    </dependency>
        <dependency>
      <groupId>org.glassfish.jersey.media</groupId>
      <artifactId>jersey-media-sse</artifactId>
      <version>${project.version}</version>
    </dependency>
     <dependency>
                <groupId>org.glassfish.jersey</groupId>
                <artifactId>jersey-bom</artifactId>
                <version>${project.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <configuration>
          <packagingExcludes>WEB-INF/classes</packagingExcludes>
          <failOnMissingWebXml>false</failOnMissingWebXml>
          <archive>
            <manifestEntries>
              <Specification-Title>Weblogic JAX-RS 2.0</Specification-Title>
              <Specification-Version>2.0</Specification-Version>
              <Implementation-Title>Weblogic JAX-RS 2.0 Reference Implementation</Implementation-Title>
              <Implementation-Version>${project.version}</Implementation-Version>
              <Extension-Name>jax-rs</Extension-Name>
            </manifestEntries>
          </archive>
              <webResources> 
            <resource>
              <filtering>true</filtering>
              <directory>src/main/webapp</directory>
              <includes>
                <include>WEB-INF/weblogic.xml</include>
              </includes>
            </resource>
          </webResources>
            </configuration>
      </plugin>
    </plugins>
  </build>
    </project>
  1. 将 weblogic 服务器中的战争部署为“库”
  2. 在我的 webservice 应用程序的 WEB-INF 文件夹下添加了一个 weblogic.xml,其中包含以下条目: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:implementation-version>2.21</wls:implementation-version>
             <exact-match>false</exact-match>
        </wls:library-ref>
    
  3. 使用下面的 pom.xml 生成了 web-service war 文件
      <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>com.cts</groupId>
  <artifactId>WLRest</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>WLRest</name>
  <build>
      <finalName>WLRest</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>

  <dependencyManagement>
      <dependencies>
          <dependency>
              <groupId>org.glassfish.jersey</groupId>
              <artifactId>jersey-bom</artifactId>
              <version>${jersey.version}</version>
              <type>pom</type>
              <scope>provided</scope>
          </dependency>
      </dependencies>
  </dependencyManagement>

  <dependencies>
      <dependency>
          <groupId>org.glassfish.jersey.containers</groupId>
          <artifactId>jersey-container-servlet-core</artifactId>
          <version>${jersey.version}</version>
          <scope>provided</scope>
      </dependency>
      <dependency>
          <groupId>org.glassfish.jersey.media</groupId>
          <artifactId>jersey-media-moxy</artifactId>
          <version>${jersey.version}</version>
          <scope>provided</scope>
      </dependency>
      <dependency>
          <groupId>com.wordnik</groupId>
          <artifactId>swagger-core_2.10</artifactId>
          <version>1.3.11</version>
          <exclusions>
              <exclusion>
                  <groupId>javax.ws.rs</groupId>
                  <artifactId>jsr311-api</artifactId>
              </exclusion>
          </exclusions>
      </dependency>
  </dependencies>
  <properties>
      <jersey.version>2.21</jersey.version>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
</project>

并使用以下 we.xml 条目:

<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
     see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.cts.WLRest</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/webapi/*</url-pattern>
    </servlet-mapping>
</web-app>

现在,当我尝试在 weblogic 中部署战争时,它会引发以下异常:

An error occurred during activation of changes, please see the log for details.
[HTTP:101216]Servlet: "Jersey Web Application" failed to preload on startup in Web application: "WLRest.war". java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map; at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:329) at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:390) at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170) at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:362) at javax.servlet.GenericServlet.init(GenericServlet.java:240) at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:299) at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:250) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120) at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57) at weblogic.servlet.internal.StubSecurityHelper.initServletInstance(StubSecurityHelper.java:94) at weblogic.servlet.internal.StubSecurityHelper.createServlet(StubSecurityHelper.java:82) at weblogic.servlet.internal.StubLifecycleHelper.createOneInstance(StubLifecycleHelper.java:74) at weblogic.servlet.internal.StubLifecycleHelper.<init>(StubLifecycleHelper.java:60) at weblogic.servlet.internal.StubLifecycleHelper.<init>(StubLifecycleHelper.java:34) at weblogic.servlet.internal.ServletStubImpl.initStubLifecycleHelper(ServletStubImpl.java:624) at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:565) at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.java:1874) at weblogic.servlet.internal.WebAppServletContext.loadServletsOnStartup(WebAppServletContext.java:1848) at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1738) at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:2740) at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1704) at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:781) at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:213) at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:208) at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:35) at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:70) at weblogic.application.internal.flow.ScopedModuleDriver.start(ScopedModuleDriver.java:212) at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:111) at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124) at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:213) at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:208) at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:35) at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:70) at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:24) at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:729) at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:35) at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:258) at weblogic.application.internal.SingleModuleDeployment.activate(SingleModuleDeployment.java:48) at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:165) at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:79) at weblogic.deploy.internal.targetserver.operations.AbstractOperation.activate(AbstractOperation.java:582) at weblogic.deploy.internal.targetserver.operations.ActivateOperation.activateDeployment(ActivateOperation.java:148) at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doCommit(ActivateOperation.java:114) at weblogic.deploy.internal.targetserver.operations.AbstractOperation.commit(AbstractOperation.java:335) at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentCommit(DeploymentManager.java:844) at weblogic.deploy.internal.targetserver.DeploymentManager.activateDeploymentList(DeploymentManager.java:1253) at weblogic.deploy.internal.targetserver.DeploymentManager.handleCommit(DeploymentManager.java:440) at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.commit(DeploymentServiceDispatcher.java:163) at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doCommitCallback(DeploymentReceiverCallbackDeliverer.java:195) at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$100(DeploymentReceiverCallbackDeliverer.java:13) at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$2.run(DeploymentReceiverCallbackDeliverer.java:68) at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:545) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256) at weblogic.work.ExecuteThread.run(ExecuteThread.java:221) 
javax.ws.rs.core.Application.getProperties()Ljava/util/Map;

我还使用了 maven 依赖树和 Jshades 来确认不同版本的 jar 之间没有冲突。对此的任何帮助或指示将不胜感激。

4

1 回答 1

1

这是因为 Weblogic 为某些库放置了自己的 jar。在这种情况下,它是旧版本的 jax-rs。您可以看到此方法是 JAX-RS 2 的新方法:

应用程序 javadoc

为了强制执行您的包,您需要在 WLS 中配置首选应用程序包:

首选应用程序包

您还需要了解这一点:

WLS 中的类加载

于 2015-08-25T06:39:39.037 回答