【发布时间】:2015-12-31 13:00:49
【问题描述】:
这不是一个web项目,但我还是在pom中添加spring-boot-starter-actuator,并指定management.port=8081,然后在CommandLineRunner的run方法的最后一个,有以下代码,
System.in.read();
当开始这个项目时,它会坚持下去。然后我将访问http://localhost:8081/configprops,但显示以下消息:
This webpage is not available
那么如何在非 Web 应用程序中访问执行器端点?
顺便说一句,我为什么要这样做,因为在启动我的项目时,它无法成功加载 yml 数据并导致 NPE。所以我想访问/configprops查看。
我的 yml 是这样的:
spring:
profiles.active: default
---
spring:
profiles: default
user:
foo:
aaa: aaa@foo.com
---
spring:
profiles: test
user:
foo:
aaa: aaa@foo.com
bbb: bbb@foo.com
@ConfigurationProperties(prefix="user", locations="user.yml")
public class UserConfig {
private HashMap<String, String> foo;
}
【问题讨论】:
-
您甚至可以在非 Web 应用程序中使用执行器。我有许多基于 CommandLineRunner 的 Spring Boot 应用程序,它们只启动一个嵌入式 Tomcat 来为执行器端点提供服务
-
@Marged 你能解释一下如何从 CommandLineRunner 启动一个嵌入式 Tomcat 来服务 /health 端点吗?
标签: spring-boot