By default, Spring Boot exposes management endpoints as JMX MBeans under the org.springframework.boot domain. Let's see how to access them via JConsole.
Actuator dependency
pom.xml<project .....> <modelVersion>4.0.0</modelVersion> <groupId>com.logicbig.example</groupId> <artifactId>accessing-actuator-jmx-end-point</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.1.RELEASE</version> </parent> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </project>
Note that spring-boot-starter-web is not necessary to access MBeans endpoints. We are just including that, otherwise we have to prevent the main() method from exiting (which can be done by some daemon thread or via pausing for command line input or may be by some UI application e.g. Swing).
The boot main class
@SpringBootApplication
public class JmxEndpointExampleMain {
public static void main(String[] args) {
SpringApplication.run(JmxEndpointExampleMain.class);
}
}
Run the main class from your IDE.
Accessing Endpoints in JConsole
Start the JConsole and look for our main class JmxEndpointExampleMain. Click on connect:
There will be a message 'Secure connection failed', just ignore that and click on 'Insecure connection'. Now click on 'MBean' tab.
Spring MBeans can be accessed under org.springframework.boot on left tree. For example, let's choose Beans/Operations/beans and on the right panel click on 'beans' button (parenthesis after 'beans' button indicate that it is a remote operation and it will return java.util.Map in response):
Let's click 'beans' operation button:
Since the 'Operation return value' window is not very friendly, copy and paste content in notepad++:
Similarly other Actuator MBeans can be access and the remote 'Operations' can be invoke which return the related information. Example ProjectDependencies and Technologies Used: - Spring Boot 2.0.1.RELEASE
Corresponding Spring Version 5.0.5.RELEASE - spring-boot-starter-actuator : Starter for using Spring Boot's Actuator which provides production
ready features to help you monitor and manage your application.
- spring-boot-starter-web : Starter for building web, including RESTful, applications using Spring
MVC. Uses Tomcat as the default embedded container.
- JDK 1.8
- Maven 3.3.9
|