7

This is not a web project, but I still add spring-boot-starter-actuator in pom, and specify management.port=8081, then in last of run method of CommandLineRunner , have below code,

System.in.read();

when started this project, it will hold on. Then I will to access http://localhost:8081/configprops, but show below message:

This webpage is not available

So how could access actuator endpoints in non-web application? BTW why I want to do so, because when started my project it can't load yml data successfully and caused NPE. So I want to access /configprops to check it.

My yml like this:

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;    
}
zhuguowei
  • 8,401
  • 16
  • 70
  • 106
  • You can use the actuator even with non-web applications. I have many CommandLineRunner based Spring Boot applications that only start an embedded Tomcat for serving the actuator endpoints – Marged Dec 31 '15 at 14:27
  • @Marged Could you explain how do you start an embedded Tomcat from CommandLineRunner to serve the /health endpoint? – RubenLaguna Oct 16 '19 at 04:58

2 Answers2

3

In a non web application you can access the Actuator endpoints with JMX. Use JConsole or JVisualVM to read the MBeans. See the Spring Boot documentation for more details: http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-jmx

dunni
  • 43,386
  • 10
  • 104
  • 99
  • thanks! but in non-web project, you still have to let process hold on by some method e.g. `Thread.sleep()` or `System.in.read()` – zhuguowei Jan 01 '16 at 03:14
  • In addition query it by jmx, does exist any other manner , e.g `System.getProperty("user.foo")` that is could output it programmatically – zhuguowei Jan 01 '16 at 03:39
1

Thanks @dunni in jconsole MBeans tab you could see

enter image description here

when click getData I got a list , one line told me

userConfig={prefix=user, properties={foo=null}}
zhuguowei
  • 8,401
  • 16
  • 70
  • 106