Spring 部署到外部 Tomcat 容器时启动执行器端口
Spring Boot Actuator port when deployed to external Tomcat container
我有一个 Spring 部署到外部 Tomcat 容器(不使用嵌入式容器)的启动应用程序,我正在尝试设置执行器。问题是 application.properties
中的 management.port
似乎没有被 Tomcat 兑现。当我 运行 Spring 使用嵌入式 Tomcat 启动时,它工作正常。
例如,在 application.properties
中设置以下内容:
management.port=9010
嵌入式容器的工作端点
http://localhost:9010/health
外部容器的非工作端点 运行正在端口 8080
http://localhost:9010/health
http://localhost:8080/health
http://localhost:9010/<appName>/health
http://localhost:8080/<appName>/health
我需要在 Tomcat 容器中进行特殊配置以公开 Spring 引导执行器端点吗?
我试过设置 MANAGEMENT_PORT
的环境变量。大多数(几乎所有)可用的文档都使用嵌入式 Tomcat,因此追踪这个问题被证明是具有挑战性的。
这个答案的第三条评论提供了一些可能的见解:,它指向一个 GitHub 文件,表明如果未设置管理端口,它将与服务器相同港口.
是的,如果您的 application.properties 正在呼叫 属性
"management.port: 9001" 和 "server.port: 9000"。然后您的应用程序端点将部署在端口 9000 上,执行器端点将部署在端口 9001 上。
所以这取决于我们。我们可以用相同的端口提及这两个属性,应用程序将正常工作。
我们不能为外部 Tomcat 容器指定额外的端口。
原因如下:https://github.com/spring-projects/spring-boot/issues/552
唯一的方法是使用上下文路径扩展端点,例如“/management”并对其应用安全性。
你 运行 Tomcat7 是哪个 Java 版本?
N.B。这都是猜测 - 我还没有能够证实这一点
如果是 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. Note that the
deprecated Tomcat 7 WebSocket API will be available.
我只能冒险猜测,Spring Boot 使用 JSR356 告诉 Web App Container "in addition to listening to the default port for the main app, also listen on port X
for actuator endpoints"... 而这不可用 运行 下 Java6
...我可能错了。
如果有人可以 confirm/deny 这种行为,我会更新此回复。
将 Tomcat 设置为使用 Java8
并删除套接字罐(tomcat7-websocket.jar
和 websocket-api.jar
罐)后,我得到了 following message from Spring:
o.s.b.a.a.EndpointWebMvcAutoConfiguration : Could not start embedded management container on different port (management endpoints are still available through JMX)
与此同时,@DecipherX 的解决方法(即不设置 management.port=9010
)将通过默认端口公开执行器端点。
如果您从配置中删除 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). If management.server.port is configured, management.endpoints.web.base-path is relative to management.server.base-path.
我在本地环境中遇到了同样的问题,
- 我通过 更改 tomcat 修复了它,(重新安装一个新的),
- 也可以通过 将 > \apache-tomcat-9.0.52\conf\serve.xml 中的默认端口更改为 8082
- 然后你可以访问你的执行器 link : localhost:8082/yourwarName/actuator/health
:) hope it helps someone one day..
我有一个 Spring 部署到外部 Tomcat 容器(不使用嵌入式容器)的启动应用程序,我正在尝试设置执行器。问题是 application.properties
中的 management.port
似乎没有被 Tomcat 兑现。当我 运行 Spring 使用嵌入式 Tomcat 启动时,它工作正常。
例如,在 application.properties
中设置以下内容:
management.port=9010
嵌入式容器的工作端点
http://localhost:9010/health
外部容器的非工作端点 运行正在端口 8080
http://localhost:9010/health
http://localhost:8080/health
http://localhost:9010/<appName>/health
http://localhost:8080/<appName>/health
我需要在 Tomcat 容器中进行特殊配置以公开 Spring 引导执行器端点吗?
我试过设置 MANAGEMENT_PORT
的环境变量。大多数(几乎所有)可用的文档都使用嵌入式 Tomcat,因此追踪这个问题被证明是具有挑战性的。
这个答案的第三条评论提供了一些可能的见解:
是的,如果您的 application.properties 正在呼叫 属性 "management.port: 9001" 和 "server.port: 9000"。然后您的应用程序端点将部署在端口 9000 上,执行器端点将部署在端口 9001 上。
所以这取决于我们。我们可以用相同的端口提及这两个属性,应用程序将正常工作。
我们不能为外部 Tomcat 容器指定额外的端口。 原因如下:https://github.com/spring-projects/spring-boot/issues/552
唯一的方法是使用上下文路径扩展端点,例如“/management”并对其应用安全性。
你 运行 Tomcat7 是哪个 Java 版本?
N.B。这都是猜测 - 我还没有能够证实这一点
如果是 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. Note that the deprecated Tomcat 7 WebSocket API will be available.
我只能冒险猜测,Spring Boot 使用 JSR356 告诉 Web App Container "in addition to listening to the default port for the main app, also listen on port X
for actuator endpoints"... 而这不可用 运行 下 Java6
...我可能错了。
如果有人可以 confirm/deny 这种行为,我会更新此回复。
将 Tomcat 设置为使用 Java8
并删除套接字罐(tomcat7-websocket.jar
和 websocket-api.jar
罐)后,我得到了 following message from Spring:
o.s.b.a.a.EndpointWebMvcAutoConfiguration : Could not start embedded management container on different port (management endpoints are still available through JMX)
与此同时,@DecipherX 的解决方法(即不设置 management.port=9010
)将通过默认端口公开执行器端点。
如果您从配置中删除 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). If management.server.port is configured, management.endpoints.web.base-path is relative to management.server.base-path.
我在本地环境中遇到了同样的问题,
- 我通过 更改 tomcat 修复了它,(重新安装一个新的),
- 也可以通过 将 > \apache-tomcat-9.0.52\conf\serve.xml 中的默认端口更改为 8082 - 然后你可以访问你的执行器 link : localhost:8082/yourwarName/actuator/health
:) hope it helps someone one day..