Search code examples
mavenspring-bootjerseymaven-3jersey-2.0

Spring Jersey - java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map


UPDATE: So I just want to point out that before I submitted this question, I attempted the solution that I've seen on similar stackoverflow questions such as this one. It was still giving me runtime errors, so I decided to write this question. mvn dependency:tree is what I was looking for so thanks @dunni. With mvn dependency:tree, I was able to find the actual name of the jersey dependency that was breaking my application and updated the exclusion by changing it from:

<exclusions>
    <exclusion>
        <groupId>javax.ws.rs</groupId>
        <artifactId>jsr311-api</artifactId>
    </exclusion>
</exclusions>

To:

<exclusions>
    <exclusion>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
    </exclusion>
</exclusions>

This works now.


For the longest time, I've been working on this Spring Jersey REST application using 1 internal company repository. Now, I found out that a library I need to use only exists in a 2nd internal company repository. I updated my .m2 -> settings.xml configuration to add the reference to the new repo like so:

<settings>
    <mirrors>
        <mirror>
            <id>internal-repository1</id>
            <name>name</name>
            <url>http://repo1.company.com/repositories/</url>
            <mirrorOf>*, !repo2</mirrorOf>
        </mirror>
    </mirrors>  
    <profiles>
        <profile>
            <id>profile</id>
            <repositories>
                <repository>
                    <id>repo1</id>
                    <name>repo1</name>
                    <url>http://repo1.company.com/repositories/</url>
                </repository>
                <repository>
                    <id>repo2</id>
                    <name>repo2</name>
                    <url>http://repo2.company.com/respositories/</url>
                </repository>
            </repositories>
        </profile>                
    </profiles>

    <activeProfiles>
        <activeProfile>profile</activeProfile>
    </activeProfiles>
</settings>

This works. I can see in the System.out that it attempts to download the repo2 exclusive dependency from repo1.company.com/repositories/. It fails, then it attempts to download it from repo2.company.com/repositories and it succeeds. The build continues, and eventually tomcat gets started up on localhost:8080 and everything is fine.

The problem is, whenever I try to access any of my Jersey REST endpoints I've set up, I get the runtime error mentioned in the question title:

ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[my.package.name] 
- Allocate exception for servlet my.package.name.JerseyConfig
java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;

I know for a fact that the issue lies somewhere in this new dependency I'm trying to use. When I comment out the dependency in my pom.xml, and re run the application, everything works fine. All REST endpoints are functional. Uncomment the dependency, re-run the application, and try to access my REST endpoints, and I get the above error.

How do I go about finding out why this dependency is breaking my Jersey application at runtime?


Solution

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