-1

i'm using spring like application container and I'm getting the following error at runtime:

   Caused by: java.lang.NoSuchMethodError: org.springframework.http.MediaType.compareTo(Lorg/springframework/http/MediaType;)I
at org.springframework.web.servlet.mvc.condition.ProducesRequestCondition.compareMatchingMediaTypes(ProducesRequestCondition.java:273)
at org.springframework.web.servlet.mvc.condition.ProducesRequestCondition.compareTo(ProducesRequestCondition.java:218)
at org.springframework.web.servlet.mvc.method.RequestMappingInfo.compareTo(RequestMappingInfo.java:217)
at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping$1.compare(RequestMappingInfoHandlerMapping.java:77)
at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping$1.compare(RequestMappingInfoHandlerMapping.java:75)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MatchComparator.compare(AbstractHandlerMethodMapping.java:367)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MatchComparator.compare(AbstractHandlerMethodMapping.java:358)
at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
at java.util.TimSort.sort(TimSort.java:220)
at java.util.Arrays.sort(Arrays.java:1512)
at java.util.ArrayList.sort(ArrayList.java:1454)
at java.util.Collections.sort(Collections.java:175)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:261)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:223)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:56)
at org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:298)
at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1091)
at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1076)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:896)

This is my dependency tree

[INFO] +- pdftron:pdftron:jar:6.6.1:compile
[INFO] +- edu.yale:its.tp.cas.client.dto:jar:3.1.0:compile
[INFO] +- log4j:log4j:jar:1.2.16:compile
[INFO] +- org.apache.openejb:javaee-api:jar:5.0-1:provided
[INFO] +- javax.servlet:jstl:jar:1.2:provided
[INFO] +- javax.servlet.jsp:jsp-api:jar:2.1:provided
[INFO] +- org.springframework:spring-core:jar:4.1.4.RELEASE:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.2:compile
[INFO] +- org.springframework:spring-expression:jar:4.1.4.RELEASE:compile
[INFO] +- org.springframework:spring-beans:jar:4.1.4.RELEASE:compile
[INFO] +- org.springframework:spring-aop:jar:4.1.4.RELEASE:compile
[INFO] |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- org.springframework:spring-context:jar:4.1.4.RELEASE:compile
[INFO] +- org.springframework:spring-context-support:jar:4.1.4.RELEASE:compile
[INFO] +- org.springframework:spring-tx:jar:4.1.4.RELEASE:compile
[INFO] +- org.springframework:spring-jdbc:jar:4.1.4.RELEASE:compile
[INFO] +- org.springframework:spring-orm:jar:4.1.4.RELEASE:compile
[INFO] +- org.springframework:spring-oxm:jar:4.1.4.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:4.1.4.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:4.1.4.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc-portlet:jar:4.1.4.RELEASE:compile
[INFO] +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.5:compile
[INFO] |  \- org.codehaus.jackson:jackson-core-asl:jar:1.9.5:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.19:compile
[INFO] +- org.springframework:spring-test:jar:4.1.4.RELEASE:test
[INFO] +- org.springframework.security:spring-security-core:jar:3.2.0.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-web:jar:3.2.0.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-config:jar:3.2.0.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-taglibs:jar:3.2.0.RELEASE:compile
[INFO] |  \- org.springframework.security:spring-security-acl:jar:3.2.0.RELEASE:compile
[INFO] +- commons-dbcp:commons-dbcp:jar:1.3:compile
[INFO] +- org.hibernate:hibernate-core:jar:3.6.9.Final:compile
[INFO] |  +- antlr:antlr:jar:2.7.6:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  +- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.6.1:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:3.6.9.Final:compile
[INFO] |  \- javassist:javassist:jar:3.12.0.GA:compile
[INFO] +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] +- org.hibernate:hibernate-validator:jar:4.2.0.Final:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.6.1:compile
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.6.1:compile
[INFO] +- javax.validation:validation-api:jar:1.0.0.GA:compile
[INFO] +- cglib:cglib-nodep:jar:2.2.2:compile
[INFO] +- javax.transaction:jta:jar:1.1:compile
[INFO] +- commons-pool:commons-pool:jar:1.5.6:compile
[INFO] +- commons-digester:commons-digester:jar:2.1:compile
[INFO] |  \- commons-beanutils:commons-beanutils:jar:1.8.3:compile
[INFO] +- commons-fileupload:commons-fileupload:jar:1.2.2:compile
[INFO] +- javax.servlet.jsp.jstl:jstl-api:jar:1.2:compile
[INFO] +- org.glassfish.web:jstl-impl:jar:1.2:compile
[INFO] +- javax.el:el-api:jar:1.0:provided
[INFO] +- joda-time:joda-time:jar:1.6:compile
[INFO] +- commons-codec:commons-codec:jar:1.6:compile
[INFO] +- org.apache.tiles:tiles-jsp:jar:2.2.2:compile
[INFO] |  +- org.apache.tiles:tiles-servlet:jar:2.2.2:compile
[INFO] |  |  \- org.apache.tiles:tiles-core:jar:2.2.2:compile
[INFO] |  \- org.apache.tiles:tiles-template:jar:2.2.2:compile
[INFO] |     \- org.apache.tiles:tiles-api:jar:2.2.2:compile
[INFO] +- commons-io:commons-io:jar:2.3:compile
[INFO] +- commons-lang:commons-lang:jar:2.6:compile
[INFO] +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] +- jsptags:pager-taglib:jar:2.0:compile
[INFO] +- org.owasp.esapi:esapi:jar:2.1.0:compile
[INFO] |  +- commons-configuration:commons-configuration:jar:1.5:compile
[INFO] |  +- commons-beanutils:commons-beanutils-core:jar:1.7.0:compile
[INFO] |  +- xom:xom:jar:1.2.5:compile
[INFO] |  +- org.beanshell:bsh-core:jar:2.0b4:compile
[INFO] |  \- org.owasp.antisamy:antisamy:jar:1.4.3:compile
[INFO] |     +- org.apache.xmlgraphics:batik-css:jar:1.7:compile
[INFO] |     |  +- org.apache.xmlgraphics:batik-ext:jar:1.7:compile
[INFO] |     |  \- org.apache.xmlgraphics:batik-util:jar:1.7:compile
[INFO] |     \- net.sourceforge.nekohtml:nekohtml:jar:1.9.12:compile
[INFO] \- junit:junit:jar:3.8.1:test

Where am I doing wrong?

Skizzo
  • 2,883
  • 8
  • 52
  • 99
  • Is this the complete stacktrace? If, no, please add the full stacktrace. – dpr Mar 06 '17 at 12:49
  • Full stacktrace added – Skizzo Mar 06 '17 at 12:54
  • It looks like some different version of `MediaType` made it to your classpath. You could try to find where it comes from in your IDE or following the answer to [this question](https://stackoverflow.com/questions/11747833/getting-filesystem-path-of-class-being-executed) – dpr Mar 06 '17 at 13:03
  • 1
    This error usually means that your code (or some library) was compiled against a different version of Spring than is used to run it. – Henry Mar 06 '17 at 13:05
  • Try deleting path org.springframework in your repo and run it again – artemisian Mar 06 '17 at 14:46
  • @Skizzo Try out deleting `org.springframework:spring-core` variations from `.m2` and then building your project to find the source of `MediaType` – Naman Mar 06 '17 at 15:52
  • @Tunaki - This isn't an exact duplicate of the other question. NoSuchMethodError is a generic exception and diagnosing them in relation to spring dependencies can be a painful process. The linked question doesn't list how to identify and solve this particular instance of the issue – beirtipol Mar 10 '17 at 12:17

1 Answers1

0

You're using mixed versions of Spring. spring-security-web 3.2.0.Release depends on spring-web 3.2.6.Release. You should update all of your spring dependencies to use a single version where possible.

https://mvnrepository.com/artifact/org.springframework.security/spring-security-web/3.2.0.RELEASE

You can catch problems like this by using the maven enforcer plugin DependencyConvergence rule: http://maven.apache.org/enforcer/enforcer-rules/dependencyConvergence.html

beirtipol
  • 823
  • 5
  • 21