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

查看:95
本文介绍了NoSuchMethodError javax.ws.rs.core.Application.getProperties()Ljava/util/Map的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying my first REST application.

下面是我的配置:

  • Java 7
  • JBoss AS 7.1
  • Jersey 2.22.2

以下是Maven下载的jar列表:

Below are list of jars downloaded by Maven:

<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>

在服务器启动时,出现以下异常:

On server starting, I am getting the below exception:

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().

According to the logs above ApplicationHandler.init() method is calling Application.getProperties().

ApplicationHandler jersey-server-2.22.2.jar 中,而Application javax.ws.rs-api-2.0.1 中罐子存在于构建路径中.

ApplicationHandler is in jersey-server-2.22.2.jar and Application is in javax.ws.rs-api-2.0.1, both jars are present in build path.

但是我仍然得到NoSuchMethodError.我已经检查了以下链接:

But still I am getting NoSuchMethodError. I have checked below links:

  • 链接1 我根本没有用招摇; /li>
  • 链接2 我看不到一个以上的Application类版本;
  • 链接3 我正在使用JRE 7和JBoss AS 7.1也与JDK 7兼容.
  • link 1 I am not using swagger at all;
  • link 2 I couldn't see more than one version of Application class;
  • link 3 I am using JRE 7 and JBoss AS 7.1 is also JDK 7 compatible.

所以我只有一个应用程序包含getProperties()方法,即使这样我也得到了NoSuchMethodError.有人可以告诉我为什么会这样吗?

So I have only one Application which contains getProperties() method and even then I am getting NoSuchMethodError. Can any one please give me reason why this is happening?

推荐答案

JBoss AS 7文档,所使用的JAX-RS规范的版本为1.1.

As mentioned in the JBoss AS 7 documentation, the version of the JAX-RS specification used is 1.1.

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

Therefore, in order to use Jsersey 2.X, which provides support for JAX-RS APIs and serves both JAX-RS 1.x and JAX-RS 2.x reference implementations, you need to exclude the conflicts with RESTEasy by adding the following to your 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 :

Also, you need to add the following to your 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论坛主题如下:

The related JBoss forum threads are the following:

  • Jersey 2 and JBoss 7
  • Jersey application on JBoss AS 7

这篇关于NoSuchMethodError javax.ws.rs.core.Application.getProperties()Ljava/util/Map的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆