REST webservice - 使用Spring Jersey插件从Jersey 1升级到Jersey 2时出错

时间:2018-01-06 22:17:05

标签: rest jersey-2.0 jboss-eap-6 jdk1.8.0 spring-jersey

我现在使用Jersey 1.8使用JBoss EAP 6.3进行Jersey Spring插件1.8,并且它可以与JDK 1.6一起使用。现在,在升级到JDK 1.8和JBoss EAP 6.4时,绑定响应 [1] 时不支持Jersey 1.0。之后我将Jersey和Jersey + Spring版本升级到2.4.1 [2] 但是我得到了"异常:java.lang.NoSuchMethodError:javax.ws。 rs.core.Application.getProperties()Ljava / util的/地图;"启动服务器时出错。有人可以让我知道如何解决这个问题     或者使用此JDK 1.8迁移实现的任何其他可能的解决方案?

  1. 尝试检查mvn依赖:树并从axis2-transport-local jar中删除了jsr311-api jar但仍然没有找到方法错误[3]
  2. 尝试注释掉" /jboss-eap-6.4 \ modules \ system \ layers \ base \ javax \ ws \ rs \ api \ main \ module.xml"中配置的资源。 [5]并在启动服务器时发现模块未找到错误。即使这不能确定它是正确的做法。

    [1]绑定错误JDK 1.8和Jersey 1.8

      

    20:01:12,484 ERROR [org.apache.catalina.core.ContainerBase。[jboss.web]。[default-host]。[/ tst02]。[jersey-serlvet]](ajp- / 10.78.180.83 :9109-14)JBWEB000236:servlet jersey-serlvet的Servlet.service()抛出异常:java.lang.AbstractMethodError   at org.codehaus.jackson.map.AnnotationIntrospector $ Pair.findSerializer(AnnotationIntrospector.java:1148)[jackson-mapper-asl-1.9.9.redhat-4.jar:1.9.9.redhat-4]   在org.codehaus.jackson.map.ser.BasicSerializerFactory.findSerializerFromAnnotation(BasicSerializerFactory.java:366)[jackson-mapper-asl-1.9.9.redhat-4.jar:1.9.9.redhat-4]   在org.codehaus.jackson.map.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:252)[jackson-mapper-asl-1.9.9.redhat-4.jar:1.9.9.redhat-4]   在org.codehaus.jackson.map.ser.StdSerializerProvider._createUntypedSerializer(StdSerializerProvider.java:782)[jackson-mapper-asl-1.9.9.redhat-4.jar:1.9.9.redhat-4]   at org.codehaus.jackson.map.ser.StdSerializerProvider._createAndCacheUntypedSerializer(StdSerializerProvider.java:735)[jackson-mapper-asl-1.9.9.redhat-4.jar:1.9.9.redhat-4]

    [2]使用2.4.1升级到Jersey和Jersey + Spring版本后出现错误

      

    06:12:53,208 ERROR [org.apache.catalina.core.ContainerBase。[jboss.web]。[default-host]。[/ tst01]](ServerService Thread Pool - 113)JBWEB000289:Servlet jersey- serlvet抛出load()异常:java.lang.NoSuchMethodError:javax.ws.rs.core.Application.getProperties()Ljava / util / Map;   在org.glassfish.jersey.server.ApplicationHandler。(ApplicationHandler.java:272)[jersey-server-2.4.1.jar:]   在org.glassfish.jersey.servlet.WebComponent。(WebComponent.java:302)[jersey-container-servlet-core-2.4.1.jar:]   在org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:167)[jersey-container-servlet-core-2.4.1.jar:]   在org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:349)[jersey-container-servlet-core-2.4.1.jar:]   在javax.servlet.GenericServlet.init(GenericServlet.java:242)[jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-2.jar:1.0.2.Final-redhat-2]   在org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1194)[jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]   在org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1100)[jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]   在org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3593)[jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]   在org.apache.catalina.core.StandardContext.start(StandardContext.java:3802)[jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]   在org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:163)[jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]   在org.jboss.as.web.deployment.WebDeploymentService.access $ 000(WebDeploymentService.java:61)[jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21 ]   在org.jboss.as.web.deployment.WebDeploymentService $ 1.run(WebDeploymentService.java:96)[jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21 ]   at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511)[rt.jar:1.8.0_151]   at java.util.concurrent.FutureTask.run(FutureTask.java:266)[rt.jar:1.8.0_151]   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)[rt.jar:1.8.0_151]   at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624)[rt.jar:1.8.0_151]   在java.lang.Thread.run(Thread.java:748)[rt.jar:1.8.0_151]   在org.jboss.threads.JBossThread.run(JBossThread.java:122)

    [4]我们模块的POM.xml Maven依赖关系

    <dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-spring3</artifactId>
    <version>2.4.1</version>
    <exclusions>
    <exclusion>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
    </exclusion>
    <exclusion>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    </exclusion>
    <exclusion>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    </exclusion>
    <exclusion>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    </exclusion>
    <exclusion>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    </exclusion>
    </exclusions>
    </dependency>
    
    <dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
    <version>2.4.1</version>
    </dependency>
    <dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-multipart</artifactId>
    <version>2.4.1</version>
    </dependency>
    <dependency>
    <groupId>org.jboss.spec.javax.ws.rs</groupId>
    <artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
    <version>1.0.0.Final</version>
    </dependency>
    

    [5] JBoss module.xml                 - &GT;          

    <dependencies>
    <module name="org.jboss.resteasy.resteasy-jaxrs" services="export"/>
    </dependencies>
    </module>
    

1 个答案:

答案 0 :(得分:0)

在我看来,您可能需要添加 jboss-deployment-structure.xml 描述符文件(请参阅here以进一步阅读)以排除添加到的JAX-RS 1.0依赖项JBoss模块的类路径。我有一个类似的问题,通过将以下文件添加到我的EAR中的META-INF目录来修复:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<sub-deployment name="TheWar.war">
    <dependencies>
        <module name="javax.jws.api" /> <!-- Required due to exclusion of javaee.api below -->
        <module name="javax.servlet.api" /> <!-- Required due to exclusion of javaee.api below -->
        <module name="javax.xml.ws.api" /> <!-- Required due to exclusion of javaee.api below -->
    </dependencies>
    <exclude-subsystems>
        <subsystem name="jaxrs" />
        <subsystem name="resteasy" />
        <subsystem name="webservices" />
    </exclude-subsystems>
    <exclusions>
        <module name="javaee.api" /> <!-- Exclude as it brings in dependency on JAX-RS 1.0 -->
        <module name="javax.ws.rs.api"/> <!-- Exclude as it brings in dependency on JAX-RS 1.0 -->
        <module name="org.jboss.resteasy.resteasy-jaxrs" /> <!-- Exclude as it brings in dependency on JAX-RS 1.0 -->
        <module name="org.jboss.as.jaxrs" /> <!-- Exclude as it brings in dependency on JAX-RS 1.0 -->
    </exclusions>
</sub-deployment>