Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails 3.3.0 on Tomcat 7.0.57

We are trying to use response.outputStream in Grails 3.3.0 under Tomcat 7.0.57. However, when any bytes are written to the stream, we get this error:

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/WriteListener

This seems to come from the 3.1 Servlet spec? But Tomcat 7 doesn't support 3.1, only 3.0. However, we've targeted the Grails app to the Tomcat version we are deploying to by doing this in dependencies:

provided "org.springframework.boot:spring-boot-starter-tomcat"

And this, later in the build.gradle file:

war {
   ext['tomcat.version'] = '7.0.57'
}

Anything else to try?

like image 225
Sean LeBlanc Avatar asked Dec 08 '25 22:12

Sean LeBlanc


1 Answers

Turns out the problem was caused by Groovy introspection upon loading the class OnCommittedResponseWrapper, which has this:

    public void setWriteListener(WriteListener writeListener) {
        this.delegate.setWriteListener(writeListener);
    }

Adding a @GrailsCompileStatic to the method(s) which use the response outputStream in ways like this:

response.outputStream << someBytes

will avoid the introspection which then makes it work on Tomcat 7.

like image 96
Sean LeBlanc Avatar answered Dec 11 '25 18:12

Sean LeBlanc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!