Spring boot 如何在非web应用程序中访问执行器端点

Spring boot 如何在非web应用程序中访问执行器端点,spring-boot,Spring Boot,这不是一个web项目,但我仍然在pom中添加了spring boot starter actuator,并指定了management.port=8081,然后在CommandLineRunner的最后一个运行方法中,有以下代码 System.in.read(); 当这个项目启动时,它将保持不变。然后我将访问http://localhost:8081/configprops,但显示以下消息: This webpage is not available 那么,如何在非web应用程序中访问执行器端

这不是一个web项目,但我仍然在pom中添加了
spring boot starter actuator
,并指定了
management.port=8081
,然后在
CommandLineRunner
的最后一个运行方法中,有以下代码

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;    
}
spring:
profiles.active:默认值
---
春天:
配置文件:默认值
用户:
傅:
aaa:aaa@foo.com
---
春天:
简介:测试
用户:
傅:
aaa:aaa@foo.com
bbb:bbb@foo.com
@配置属性(前缀=“user”,位置=“user.yml”)
公共类UserConfig{
私有HashMap-foo;
}

在非web应用程序中,您可以使用JMX访问执行器端点。使用JConsole或JVisualVM读取MBean。有关更多详细信息,请参阅Spring引导文档:

感谢您在jconsole MBeans选项卡中看到的@dunni

当单击getData时,我得到了一个列表,一行告诉我

userConfig={prefix=user, properties={foo=null}}

即使在非web应用程序中也可以使用执行器。我有许多基于CommandLineRunner的Spring引导应用程序,它们只启动一个嵌入式Tomcat来为执行器提供服务endpoints@Marged您能解释一下如何从CommandLineRunner启动嵌入式Tomcat来服务于/health端点吗?谢谢!但在非web项目中,您仍然必须通过一些方法让进程保持运行,例如
Thread.sleep()
System.in.read()
除了通过jmx查询它之外,还存在任何其他方式,例如
System.getProperty(“user.foo”)
,可以通过编程方式输出它