简体   繁体   中英

Spring boot actuator in console application

I have a console application using Spring. My application is connecting on a database and a JMS server. I would like to know at the start up of my application, if it is well connected to the databse and the JMS. I know that spring-boot-actuator do that efficiently and esealy, but it expose rest endpoints. I would like to know if it's possible to get Spring actuator's beans to get status informations, database and JMS status.

Is it possible ?

Thank you.

According to the documentation , endpoints can be exposed through HTTP or JMX. By default, Spring will expose actuator endpoints over JMX unless you configure it not to do so.

There is a table showing which endpoints are enabled in JMX and HTTP by default. If you want to enable them on HTTP, there are several security settings you should be aware of before exposing them (see docs link above).

In order to expose actuator endpoints over HTTP, you'll need to include the spring-starter-web start in your build.

Gradle:

compile('org.springframework.boot:spring-boot-starter-web')

Maven:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

Again, check the security settings before doing this. Newer versions of boot should give you a good safe set of defaults.

About your second question: Yes, springs actuators provide autoconfigured health indicators when they are found on classpath, see this list for more details (datasource and JMS is provided).

But you can also easily implement your own status informations by just implementing HealthIndicator and adding it as a @Component , more details can be found here .

You can expose them either with REST or with JMX, the exposure can be configured via application.properties , details can be found in the docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM