当前位置: 首页 > 知识库问答 >
问题:

在WebLogic12c中部署基于Jersey的Restful webservice

史朗
2023-03-14

我在eclipse中使用“Jersey”原型开发了一个非常小的restful Web服务,并且在Tomcat中成功地部署了该服务。但是,我无法在WebLogic12c中部署它。这是我到目前为止所尝试的:

  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>

在我的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>
      <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中部署the war时,它抛出了以下异常:

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之间没有冲突。任何有关这方面的帮助或指针将非常感谢。

共有1个答案

卢鸿彩
2023-03-14

这是因为Weblogic为某些库放置了自己的JAR。在本例中,它是JAX-RS的旧版本。您可以看到,这个方法对于JAX-RS2来说是新的:

应用程序javadoc

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

你还需要明白这一点:

WLS中的类加载

 类似资料:
  • 我有这个问题,一个应用程序耳朵有这个错误,我是一个weblogic12c的新管理员,有人帮助我吗??? 这是一个标准安装Weblogic 12c

  • 我有一个工作的Jersey JAX-RS应用程序,我刚刚修改了它,以便在一个构造函数中注入一个依赖项。我试图在GlassFish上部署它,但后来我在这里遇到了这个问题。 所以我考虑在Tomcat上尝试一下,因为我认为这是HK2和CDI如何相互冲突的问题,但它在Tomcat上也不起作用,所以当我部署war文件时,我得到了这个错误: 下面是DI的实现: 我是这样注射的: 其余的代码以前工作得很好,只是

  • 同时在WebLogic12c中部署应用程序。我有个例外。我是weblogic12c的新手。有什么建议吗??

  • 我想在weblogic中部署一个EAR,并且该EAR可以包含基于属性文件中的属性的WAR。如果属性设置为true,则部署战争,否则不部署。 如何在weblogic 12c中限制基于属性的war部署?

  • 根据本教程,我最近开始使用泽西岛。我已经在Web中配置了服务/包名称.xml好吧,现在的事情是我得到了一个javax.servlet.Servlet例外:Servlet.init()例外,下面有以下堆栈跟踪: 这是我的Jes.java类文件: 还有网络.xml 这是我的应用程序设置: Apache Tomcat 6.0 < br > Jersey-core-1.8 . jar < br > Jer

  • 我正在使用下面的命令检查12C中Weblogic服务器的状态,该命令在10.x Weblogic中正常工作 java weblogic.admin-URL t3:/$IP:$端口getstate-username$username-password$password 我将类路径设置如下导出classpath=$WL_HOME/server/lib/weblogic.jar