[英]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.我有一个部署到外部 Tomcat 容器(不使用嵌入式容器)的 Spring Boot 应用程序,我正在尝试设置执行器。 The problem is that the management.port
in application.properties
does not seem to be honored by Tomcat.问题是application.properties
中的management.port
似乎不受 Tomcat 的尊重。 When I run Spring Boot with embedded Tomcat it works just fine.当我使用嵌入式 Tomcat 运行 Spring Boot 时,它工作得很好。
For example, having the following set in application.properties
:例如,在application.properties
设置以下内容:
management.port=9010
Working endpoints for embedded container嵌入式容器的工作端点
http://localhost:9010/health
Non-working endpoints for external container running on port 8080
在端口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?我需要在 Tomcat 容器中进行特殊配置来公开 Spring Boot 执行器端点吗?
I've tried setting an environment variable of MANAGEMENT_PORT
.我试过设置MANAGEMENT_PORT
的环境变量。 Most (almost all) of the documentation available is using the embedded Tomcat, so tracking down this issue has proved to be challenging.大多数(几乎所有)可用文档都使用嵌入式 Tomcat,因此事实证明,追踪此问题具有挑战性。
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.关于这个答案的第三条评论提供了一些可能的见解: https : //stackoverflow.com/a/28689853/2601060 ,它指向一个 GitHub 文件,表明如果未设置管理端口,它将与服务器端口相同.
We cannot specify an additional port with an external Tomcat container.我们不能为外部 Tomcat 容器指定额外的端口。 Here is why : https://github.com/spring-projects/spring-boot/issues/552这就是原因: 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.唯一的方法是使用上下文路径扩展端点,比如“/management”并对其应用安全性。
Yes, if your application.properties is having property called "management.port: 9001" and "server.port: 9000".是的,如果您的 application.properties 具有名为“management.port: 9001”和“server.port: 9000”的属性。 Then your application end-points will deploy on port 9000 and actuator end-points will deployed on port 9001.然后您的应用程序端点将部署在端口 9000 上,执行器端点将部署在端口 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?您在什么 Java 版本下运行 Tomcat7?
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:如果是Java6
(我猜是因为我遇到了类似的问题),我怀疑它与以下消息有关:
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.信息:在 Java 6 上运行时,JSR 356 WebSocket (Java WebSocket 1.1) 支持不可用。要抑制此消息,请在 Java 7 上运行 Tomcat,从 $CATALINA_HOME/lib 中删除 WebSocket JAR 或将 WebSocket JAR 添加到 tomcat.util $CATALINA_BASE/conf/catalina.properties 中的 .scan.DefaultJarScanner.jarsToSkip 属性。 Note that the deprecated Tomcat 7 WebSocket API will be available.请注意,已弃用的 Tomcat 7 WebSocket API 将可用。
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.我只能猜测,Spring Boot 使用的JSR356告诉 Web App 容器“除了侦听主应用程序的默认端口外,还侦听执行器端点的端口X
”……这不是可在Java6
下运行...我可能错了。
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 :将 Tomcat 设置为使用Java8
并删除套接字 jar( tomcat7-websocket.jar
和websocket-api.jar
jar)后,我从 Spring收到以下消息:
osbaaEndpointWebMvcAutoConfiguration : Could not start embedded management container on different port (management endpoints are still available through JMX) osbaaEndpointWebMvcAutoConfiguration :无法在不同端口上启动嵌入式管理容器(管理端点仍可通过 JMX 使用)
In the meantime, @DecipherX's workaround (ie don't set management.port=9010
) will expose your actuator endpoints through the default port.同时,@DecipherX 的解决方法(即不设置management.port=9010
)将通过默认端口公开您的执行器端点。
If you remove the management.server.port
from your configuration, the actuator will be deployed under the servlet context path in external Tomcat.如果您从配置中删除management.server.port
,则执行器将部署在外部 Tomcat 中的 servlet 上下文路径下。
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).除非已将管理端口配置为使用不同的 HTTP 端口公开端点,否则 management.endpoints.web.base-path 相对于 server.servlet.context-path(Servlet Web 应用程序)或 spring.webflux.base-path(反应式 Web 应用程序)。 If management.server.port is configured, management.endpoints.web.base-path is relative to management.server.base-path.如果配置了 management.server.port,则 management.endpoints.web.base-path 相对于 management.server.base-path。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.