3

I suppose this is some kind of dependency problem so here is my tree:

[INFO] Sikor:BrowserGame:war:1.0-SNAPSHOT
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- org.springframework:spring-context:jar:4.1.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.1.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.1.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-core:jar:4.1.1.RELEASE:compile
[INFO] |  |  \- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] |  \- org.springframework:spring-expression:jar:4.1.1.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:4.1.1.RELEASE:compile
[INFO] |  \- org.springframework:spring-web:jar:4.1.1.RELEASE:compile
[INFO] +- org.springframework:spring-context-support:jar:4.1.1.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-web:jar:3.2.5.RELEASE:compile
[INFO] |  +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  \- org.springframework.security:spring-security-core:jar:3.2.5.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-config:jar:3.2.5.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-taglibs:jar:3.2.5.RELEASE:compile
[INFO] |  \- org.springframework.security:spring-security-acl:jar:3.2.5.RELEASE:compile
[INFO] +- org.thymeleaf:thymeleaf-spring4:jar:2.1.3.RELEASE:compile
[INFO] |  \- org.thymeleaf:thymeleaf:jar:2.1.3.RELEASE:compile
[INFO] |     +- ognl:ognl:jar:3.0.6:compile
[INFO] |     \- org.unbescape:unbescape:jar:1.0:compile
[INFO] +- org.thymeleaf.extras:thymeleaf-extras-springsecurity3:jar:2.1.1.RELEASE:compile
[INFO] +- nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:jar:1.2.7:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:4.3.5.FINAL:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] |  +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:4.3.5.Final:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.4.Final:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.0.Final:compile
[INFO] |  \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] +- org.hibernate:hibernate-validator:jar:4.3.2.Final:compile
[INFO] |  \- javax.validation:validation-api:jar:1.0.0.GA:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.32:compile
[INFO] +- org.springframework:spring-orm:jar:4.1.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-jdbc:jar:4.1.1.RELEASE:compile
[INFO] |  \- org.springframework:spring-tx:jar:4.1.1.RELEASE:compile
[INFO] +- org.springframework.data:spring-data-jpa:jar:1.6.4.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-commons:jar:1.8.4.RELEASE:compile
[INFO] |  +- org.aspectj:aspectjrt:jar:1.8.1:compile
[INFO] |  \- org.slf4j:jcl-over-slf4j:jar:1.7.7:runtime
[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:provided
[INFO] +- org.slf4j:slf4j-api:jar:1.7.5:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.6.1:compile
[INFO] |  \- log4j:log4j:jar:1.2.16:compile
[INFO] \- javax.mail:mail:jar:1.4:compile
[INFO]    \- javax.activation:activation:jar:1.1:compile

From what I found out, spring 4.1.1 is supposed to work with javax.servlet 3.1.0 but I'm getting java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus()I when calling response.getStatus() inside my interceptor.
I'd be glad if someone could help. Thanks in advance.

EDIT: Added web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/config/mvc-dispatcher-servlet.xml</param-value>
        </init-param>
        <init-param>
            <param-name>throwExceptionIfNoHandlerFound</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/config/root-context.xml
        </param-value>
    </context-param>

</web-app>



EDIT2: Changed the following:

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

to:

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

but I'm still getting the error when calling response.getStatus();

Sikor
  • 11,628
  • 5
  • 28
  • 43
  • 2
    Have you checked the Servlet version you're using in web.xml? – Luiggi Mendoza Dec 02 '14 at 19:35
  • 1
    Yes, this sort of error almost always means that the code was compiled against one version of a dependency but ended up running against a different version of that dependency. It's almost certainly the case that servlet-api 3 is _not_ what's being provided at runtime. – Matt Ball Dec 02 '14 at 19:38
  • Added my web.xml. I tried changing web-app version to 3.1 but it gives me an error so changed to 3.0 but NoSuchMethodError is still there. – Sikor Dec 02 '14 at 19:45
  • 1
    You should know that there are two changes to do: `xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"` and `version="3.0"`. – Luiggi Mendoza Dec 02 '14 at 19:55
  • I changed both of them of course. When changing to 3.0 it compiles, but NoSuchMethodError still exists. In my second approach I changed xsd to 3.1 but when changing version to 3.1 it says: wrong attribute value. – Sikor Dec 02 '14 at 19:58
  • Tried another solution in Edit2 by changing from java.sun to xlmns.jcp.org and now it compiles but the main problem is still here. Any tips would be appreciated. – Sikor Dec 02 '14 at 20:09
  • It could be `ClassLoader` issue. Very likely your app server is using it's own version of servlet.jar which is incompatible with yours. Depend on which app server you are using, there are different way to handle this. The most common one is to configure the class loader to load your version of servlet.jar before loading built-in one from the app server. – DJ. Dec 02 '14 at 20:19
  • 1
    Are you perhaps deploying into container which does not support Servlet API 3.0 yet? Can you have a look at the servlet.jar provided by your container? What do you use as container? – Michal Dec 02 '14 at 20:21
  • @DJ -no, you cannot do this with API jar like servlet.jar. In another words, you cannot make e.g. old tomcat 4.x JEE 6 compatible just by putting 3.1 servlet.jar into your war. – Michal Dec 02 '14 at 20:25
  • Okay, thanks to your tips I was able to fix this. I was running the app on a simple tomcat:run. I changed it to create a war and made sure it's running on Tomcat 7.0.54 and now it works just fine. Thank you all for the comments. – Sikor Dec 02 '14 at 20:40

3 Answers3

5

I was running my app on a simple tomcat:run. After deploying it to war and making sure I'm using Tomcat 7 everything is fine. Thanks to all commentators, you pointed me at the right direction. Cheers.

EDIT : Keep in mind that tomcat 7 does not support servlets 3.1 so you either have to use servlet 3.0 with tomcat 7 or servlet 3.1 and tomcat 8.

Sikor
  • 11,628
  • 5
  • 28
  • 43
1

This is a problem that has been resolved in version 4.1.1 release, use version 4.1.1 or higher, or set the DispatcherServlet bean, set publishEvents to false.

This is a problem that has been resolved in version 4.1.1 release, use version 4.1.1 or higher, or set the DispatcherServlet bean, set publishEvents to false.

Unheilig
  • 16,196
  • 193
  • 68
  • 98
Jeremias Santos
  • 377
  • 3
  • 5
1

I had the same issue and it was related with groovy. I added groovy to the classpath (external libraries) using my IDE from sdk sources instead of using maven or gradle dependencies.

It seems HttpServletResponse which comes with a dependency of groovy doesn't have the getStatus() methods. So finally, I removed from the classpath and add it in maven and it works.

Pau
  • 14,917
  • 14
  • 67
  • 94