NoSuchMethodError javax.ws.rs.core.Application.getProperties()Ljava / util / Map

时间:2016-04-23 16:18:52

标签: rest jersey jax-rs jboss7.x

我正在尝试我的第一个REST应用程序。

以下是我的配置:

  • Java 7
  • JBoss AS 7.1
  • Jersey 2.22.2

以下是Maven下载的罐子列表:

enter image description here

<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>org.prasad</groupId>
<artifactId>messenger</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>messenger</name>

<build>
    <finalName>messenger</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>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <!-- use the following artifactId if you don't need servlet 2.x compatibility -->
        <!-- artifactId>jersey-container-servlet</artifactId -->
        <exclusions>
</exclusions>
    </dependency>
    <!-- uncomment this to get JSON support
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-moxy</artifactId>
    </dependency>
    -->
</dependencies>
<properties>
    <jersey.version>2.22.2</jersey.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

在服务器启动时,我收到以下异常:

21:14:29,013 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/messenger]] (MSC service thread 1-1) StandardWrapper.Throwable: java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
    at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:331) [jersey-server-2.22.2.jar:]
    at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:392) [jersey-container-servlet-core-2.22.2.jar:]
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:177) [jersey-container-servlet-core-2.22.2.jar:]
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:369) [jersey-container-servlet-core-2.22.2.jar:]
    at javax.servlet.GenericServlet.init(GenericServlet.java:242) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3655) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3873) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_79]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_79]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_79]

根据上面的日志ApplicationHandler.init()方法正在调用Application.getProperties()

ApplicationHandler位于 jersey-server-2.22.2.jar 中,Application位于 javax.ws.rs-api-2.0.1 ,两个jar都存在于构建路径中。

但我仍然得到NoSuchMethodError。我已查看以下链接:

  • link 1我根本没有使用招摇;
  • link 2我看不到Application类的多个版本;
  • link 3我使用的是JRE 7,JBoss AS 7.1也兼容JDK 7.

所以我只有一个Application,其中包含getProperties()方法,即便如此,我还是NoSuchMethodError。任何人都可以告诉我为什么会这样吗?

1 个答案:

答案 0 :(得分:5)

正如JBoss AS 7 documentation中所提到的,使用的JAX-RS规范的版本是1.1。

因此,为了使用Jsersey 2.X,它提供对JAX-RS API的支持并同时提供JAX-RS 1.xJAX-RS 2.x参考实现,您需要通过添加以下内容来排除与RESTEasy的冲突关注 WEB-INF / jboss-deployment-structure.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <!-- Exclude RestEasy conflicts -->
            <module name="javaee.api" />
            <module name="javax.ws.rs.api"/>
            <module name="org.jboss.resteasy.resteasy-jaxrs" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

此外,您需要将以下内容添加到 web.xml

<context-param>
    <param-name>resteasy.scan</param-name>
    <param-value>false</param-value>
</context-param>
<context-param>
    <param-name>resteasy.scan.providers</param-name>
    <param-value>false</param-value>
</context-param>
<context-param>
    <param-name>resteasy.scan.resources</param-name>
    <param-value>false</param-value>
</context-param>

相关的JBoss论坛主题如下: