Search code examples
spring-bootgrailsportclasscastexceptionhealth-check

management endpoints throwing GroovyCastException when served on different port


I have the following health management endpoints in my application.yml file

management:
  endpoints:
    health:
      sensitive: false
    web:
      base-path: /
        

and I have an interceptor with the following code

class TestInterceptor {

  TestInterceptor() {
    matchAll()
  }

  boolean before() {
    if (request.forwardURI?.endsWith('.json')) {
      // ... some code
      return false
    }
    true
  }
}

this is working great. The application is working on 8080.

But as soon as I change the port of management endpoints (so that health check is served on a different port), the following code

management:
  server:
    port: 8989
  endpoints:
    health:
      sensitive: false
    web:
      base-path: /

Ref# https://docs.spring.io/spring-boot/docs/2.1.7.RELEASE/reference/html/production-ready-monitoring.html

then the application is throwing a cast exception when accessing the request object in the interceptor

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'Request(GET //localhost:8989/testApp/health)@68117e64' with class 'org.springframework.web.context.request.ServletRequestAttributes' to class 'org.grails.web.servlet.mvc.GrailsWebRequest'

any suggestion to fix the issue.

(Grails 4.0.12, Groovy 2.5.14 and Java 11)


Solution

  • Upgrade to Grails 5. The above functionality working fine with that.