Java RESTful web服务,Jersey 2.23.2
我正在尝试创建一个简单的RESTful web应用程序。为此,我使用jersey quickstart webapp原型创建了一个新的Maven项目(Eclipse)。部署时,我收到以下错误: 错误[org.apache.catalina.core.ContainerBase.[jboss.web].[default host].[test]](MSC服务线程1-4)StandardWrapper.Throwable:java.lang.NoSuchMethodError:javax.ws.rs.core.Application.getProperties()Ljava/util/Map 我的Maven依赖项、pPOM和web.xml如下所示:Java RESTful web服务,Jersey 2.23.2,java,maven,jboss7.x,jersey-2.0,Java,Maven,Jboss7.x,Jersey 2.0,我正在尝试创建一个简单的RESTful web应用程序。为此,我使用jersey quickstart webapp原型创建了一个新的Maven项目(Eclipse)。部署时,我收到以下错误: 错误[org.apache.catalina.core.ContainerBase.[jboss.web].[default host].[test]](MSC服务线程1-4)StandardWrapper.Throwable:java.lang.NoSuchMethodError:javax.ws.rs
4.0.0
com.example
测试
战争
0.0.1-快照
测试
测试
org.apache.maven.plugins
maven编译器插件
2.5.1
真的
1.7
1.7
org.glassfish.jersey
针织面料
${jersey.version}
聚甲醛
进口
org.glassfish.jersey.containers
jersey容器servlet核心
2.23.2
UTF-8
Jersey Web应用程序
org.glassfish.jersey.servlet.ServletContainer
jersey.config.server.provider.packages
com.example.test
1.
Jersey Web应用程序
/webapi/*
轻松扫描
假的
resteasy.scan.providers
假的
resteasy.scan.resources
假的
目标是远程JBoss 7.0.2服务器
除了稍微修改web.xml之外,我没有对默认项目做任何其他修改。我搜索过类似的线程,但似乎没有任何帮助(我可能遗漏了一些我目前没有看到的细节)。在这些情况下,通常是JAR冲突。从eclipse中搜索类型(Ctrl-Shift T)
javax.ws.rs.core.Application
。如果获得链接到项目的不同版本的多个副本,则可能必须删除其他版本。此外,请尝试清除本地Maven repo并再次运行mvn clean软件包。正如Vasan指出的,同一类的至少两个不同版本位于类路径上,您可能会遇到与此处答案中提到的问题相同的问题:,执行mvn依赖项:树检查是否存在依赖项conflict@Vasan我按照您的建议做了,只显示了一个副本,它指向JAX-RS2.0。1@qingl97我已经检查了依赖关系层次结构中的依赖关系冲突,只有出现的冲突提到了已经使用的相同版本。在这些情况下,我的依赖层次结构通常是JAR冲突。从eclipse中搜索类型(Ctrl-Shift T)javax.ws.rs.core.Application
。如果获得链接到项目的不同版本的多个副本,则可能必须删除其他版本。此外,请尝试清除本地Maven repo并再次运行mvn clean软件包。正如Vasan指出的,同一类的至少两个不同版本位于类路径上,您可能会遇到与此处答案中提到的问题相同的问题:,执行mvn依赖项:树检查是否存在依赖项conflict@Vasan我按照您的建议做了,只显示了一个副本,它指向JAX-RS2.0。1@qingl97我已经检查了依赖关系层次结构中的依赖关系冲突,只有出现的冲突提到了已经使用的相同版本。我的依赖层次结构是
<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.example</groupId>
<artifactId>test</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>test</name>
<build>
<finalName>test</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 -->
</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.23.2</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<?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.example.test</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>
<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>
</web-app>