Java Jersey应用程序启动时的NoSuchMethodError [英] NoSuchMethodError on startup in Java Jersey app
问题描述
尝试在Tomcat上启动Jersey应用程序时,我遇到了一个非常奇怪的错误。相同的代码适用于其他计算机。我尝试重新安装tomcat,我所有的maven依赖项,甚至是Eclipse和Java本身,没有运气。我认为看起来好像是一个糟糕的泽西版本?
I've been getting a very strange error when trying to start a Jersey app on Tomcat. The same code works on other computers. I tried reinstalling tomcat, all my maven dependencies, even Eclipse and Java itself, no luck. It seems like a bad Jersey version is being loaded, I think?
任何正确方向的指针都会受到赞赏。
Any pointers in the right direction will be appreciated.
这是有效的pom: http://pastebin.com/NacsWTjz
实际的pom: http://pastebin.com/H6sHe4ce
2015-02-13 13:43:40,870 [localhost-startStop-1] ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/middleware-server] - StandardWrapper.Throwable
java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:304)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:285)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:311)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:358)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1031)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4901)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5188)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
推荐答案
注意:请参阅上述评论以获取进一步的讨论和提示。
Note: Please see above comments for further discussion and tips.
此错误通常意味着您同时拥有JAX-RS 1和JAX-RS 2 jar在类路径上。 Jersey 2使用JAX-RS 2( javax.ws.rs-api-2.0.1.jar
),但是如果你有 jsr311-api .jar
也是JAX-RS 1,每个jar中都有一个 javax.ws.rs.core.Application
。但是 jsr311-api
应用程序
没有方法 getProperties()
(因此 NoSuchMethodError
)。
This error usual means that you have a both a JAX-RS 1 and JAX-RS 2 jar on the classpath. Jersey 2 uses JAX-RS 2 (javax.ws.rs-api-2.0.1.jar
), but if you have the jsr311-api.jar
also, which is JAX-RS 1, there is a javax.ws.rs.core.Application
in each jar. But the jsr311-api
Application
doesn't have the method getProperties()
(hence NoSuchMethodError
).
我得出结论,你需要做的就是将上面的排除添加到swagger依赖项中。 Jackson 2.0提供程序(依赖于JAX-RS 1)似乎被2.4.1提供程序(使用新版本)覆盖。所以我们不需要自己添加它。当它被覆盖时,它似乎留下了 jsr311-api.jar
。因此,如果我们排除它,没有人可以尝试使用它,这看起来是当前的问题
I've come to the conclusion that all you need to do is add the above exclusion to the swagger dependency. The Jackson 2.0 provider (which depends on JAX-RS 1) seems to be overridden by a 2.4.1 provider (which uses the new version). So we don't need to add it ourselves. When it's overridden, it seems to leave behind the jsr311-api.jar
. So if we exclude it, no one can attempt to use it, which looks to be the current problem
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-core_2.10</artifactId>
<version>1.3.11</version>
<exclusions>
<exclusion>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</exclusion>
</exclusions>
</dependency>
这篇关于Java Jersey应用程序启动时的NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!