简体   繁体   中英

Spring Boot Actuator port when deployed to external Tomcat container

I have a Spring Boot application that is deployed to an external Tomcat container (not using the embedded container), and am trying to get the actuator set up. The problem is that the management.port in application.properties does not seem to be honored by Tomcat. When I run Spring Boot with embedded Tomcat it works just fine.

For example, having the following set in application.properties :

management.port=9010

Working endpoints for embedded container

  • http://localhost:9010/health

Non-working endpoints for external container running on port 8080

  • http://localhost:9010/health
  • http://localhost:8080/health
  • http://localhost:9010/<appName>/health
  • http://localhost:8080/<appName>/health

Is there a special configuration I need in the Tomcat container to expose a Spring Boot actuator end point?

I've tried setting an environment variable of MANAGEMENT_PORT . Most (almost all) of the documentation available is using the embedded Tomcat, so tracking down this issue has proved to be challenging.

The third comment on this answer provided some possible insight: https://stackoverflow.com/a/28689853/2601060 , which points to a GitHub file indicating that if the management port is not set, it will be the same as the server port.

We cannot specify an additional port with an external Tomcat container. Here is why : https://github.com/spring-projects/spring-boot/issues/552

The only way is to extend the endpoints using a context path, say "/management" and apply security on it.

Yes, if your application.properties is having property called "management.port: 9001" and "server.port: 9000". Then your application end-points will deploy on port 9000 and actuator end-points will deployed on port 9001.

So its up to us. We can mention both properties with same port, application will works correctly.

What Java version are you running Tomcat7 under?

NB This is all speculation - I haven't been able to verify this yet

If it's Java6 (and I'm guessing it is because I'm getting a similar issue), I suspect it's related to the following message:

INFO: JSR 356 WebSocket (Java WebSocket 1.1) support is not available when running on Java 6. To suppress this message, run Tomcat on Java 7, remove the WebSocket JARs from $CATALINA_HOME/lib or add the WebSocket JARs to the tomcat.util.scan.DefaultJarScanner.jarsToSkip property in $CATALINA_BASE/conf/catalina.properties. Note that the deprecated Tomcat 7 WebSocket API will be available.

I can only hazard a guess, that Spring Boot use's JSR356 to tell the Web App Container to "in addition to listening to the default port for the main app, also listen on port X for actuator endpoints"... and this isn't available running under Java6 ... I'm probably wrong.

If anyone could confirm/deny this behaviour, I'll update this response.

After setting Tomcat to use Java8 , and removing the socket jars ( tomcat7-websocket.jar & websocket-api.jar jars), I get the following message from Spring :

osbaaEndpointWebMvcAutoConfiguration : Could not start embedded management container on different port (management endpoints are still available through JMX)

In the meantime, @DecipherX's workaround (ie don't set management.port=9010 ) will expose your actuator endpoints through the default port.

If you remove the management.server.port from your configuration, the actuator will be deployed under the servlet context path in external Tomcat.

http://<--domain-->/<--servlet-context-->/actuator/health

Unless the management port has been configured to expose endpoints by using a different HTTP port, management.endpoints.web.base-path is relative to server.servlet.context-path (Servlet web applications) or spring.webflux.base-path (reactive web applications). If management.server.port is configured, management.endpoints.web.base-path is relative to management.server.base-path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM