java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30723370/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map
提问by Bhushan
I am trying to deploy my first rest application using jersey 2.17.
我正在尝试使用 jersey 2.17部署我的第一个休息应用程序。
I am using Maven, GlassFish 3.1.2.2 for deployment.
我正在使用 Maven、GlassFish 3.1.2.2 进行部署。
Application runs in eclipse (tomcat), but gives following error when deploying through glassfish admin console.
应用程序在 eclipse (tomcat) 中运行,但在通过 glassfish 管理控制台部署时出现以下错误。
Error occurred during deployment: Exception while loading the app :
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException:
java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;.
Please see server.log for more details.
pom.xml
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>JerseyExample</groupId>
<artifactId>JerseyExample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.17</version>
</dependency>
</dependencies>
</project>
web.xml
网页.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>JerseyExample</display-name>
<servlet>
<servlet-name>MyJerseyExample</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>jerseyExample.resource</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyJerseyExample</servlet-name>
<url-pattern>/example/*</url-pattern>
</servlet-mapping>
</web-app>
回答by Himanshu Bhardwaj
Ok looked at your issue. The External Glassfish v 3.1.2.2 that you are using is JAVA-EE 6 compatible. And the one through which you are running your app in eclipse is JAVA-EE 7 compatible.
好的看着你的问题。您使用的外部 Glassfish v 3.1.2.2 与 JAVA-EE 6 兼容。您在 Eclipse 中运行您的应用程序的方法是与 JAVA-EE 7 兼容的。
Have a look at both the java docs:
看看两个java文档:
Application class Java Doc for EE6
Application class Java Doc for EE7
You will see that the getProperties method got introduced in JAVA-EE 7.
您将看到 JAVA-EE 7 中引入了 getProperties 方法。
Simply upgrade to glassfish version-4.x that is compatible with JAVA-EE 7. Assuming nothing else breaks should be good.
只需升级到与 JAVA-EE 7 兼容的 glassfish 版本 4.x。假设没有其他问题应该很好。