NoSuchMethodError on startup in Java Jersey app
Note: Please see above comments for further discussion and tips.
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
).
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>
Tomcat Jersey NoSuchMethodError
There are several issues:
You must not put application jars inside tomcat's
./lib
folder. Instead you should add those jars as dependencies for each application inside<WAR>/WEB-INF/lib
In that way your applications will be independent and will be able to use different versions of those libraries.Make sure you do not package several versions of the same dependency, which will most probably cause various class-loading issues such as
ClassNotFoundException
,NoClasDefFoundError
andNoSuchMethodError
For instance you have jakarta.ws.rs-api
wich is Jax-Rs version 2, but you also have jsr311-api
which is Jax-Rs version 1.
So in your case, some jersey code tries to call getProperties() which was introduced in JaxRs-2, but the JVM has loaded the Application
class from jsr311-api
which is JaxRs-1 where that method does not exist.So removing the jsr311-api
jar should fix the problem.
Spring Jersey - java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map
By Seeing the error I can guess that there are some conflicts in jar files Please check if 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().
Another Guice + Jersey error NoSuchMethodError
Based on what you said I believe the fix is to use the 2.4.0-b31 version of the guice-bridge
Related Topics
How to Autowire Bean of Generic Type <T> in Spring
How to Check a Uploaded File Whether It Is an Image or Other File
Parsing JSON Array Within JSON Object
How to Use the Jersey JSON Pojo Support
Waiting at Sun.Misc.Unsafe.Park(Native Method)
Change Database Schema Used by Spring Boot
Differencebetween Canonical Name, Simple Name and Class Name in Java Class
JPA How to Make Composite Foreign Key Part of Composite Primary Key
How to Stop a Thread Created by Implementing Runnable Interface
How to Get the Current Date and Time
Hashmap to Return Default Value for Non-Found Keys
Import Sun.Misc.Base64Encoder Results in Error Compiled in Eclipse
Pass Data from Java Servlet to Jsp
Remove Elements from a Hashset While Iterating
Whats the Best Way to Recursively Reverse a String in Java
Where Is the Correct Location to Put Log4J.Properties in an Eclipse Project