ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

Spring-boot读书笔记一@JMXEndpoint

Spring-boot读书笔记一@JMXEndpoint

@JmxEndpoint Details:
@JmxEndpoint is a Spring Boot Actuator annotation that creates custom endpoints accessible only through JMX (Java Management Extensions), not via HTTP/web.

Key Differences:
Feature @Endpoint @JmxEndpoint
Access HTTP + JMX JMX only
URL /actuator/course N/A
JMX org.springframework.boot:type=Endpoint,name=Course org.springframework.boot:type=Endpoint,name=Course
Web exposure Yes No
Usage Example:

@Component
@JmxEndpoint(id = "course")
public class CourseJmxEndpoint {@Autowiredprivate CourseRepository courseRepository;@ReadOperationpublic List<String> getCourseNames() {// Only accessible via JMX, not HTTPreturn courseRepository.findAll().stream().map(Course::getName).collect(Collectors.toList());}@WriteOperationpublic void updateCourse(@Selector String courseName, String newDescription) {// JMX-only write operation}
}

Accessing JMX Endpoints:
1. JConsole (Built into JDK):

  • Run jconsole
  • Connect to your Spring Boot application
  • Navigate to MBeans → org.springframework.boot → Endpoint → Course

2. JMX Client Code:

MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectName objectName = new ObjectName("org.springframework.boot:type=Endpoint,name=Course");

3. Application Properties:


# Enable JMX (enabled by default)
spring.jmx.enabled=true
# Expose JMX endpoints
management.endpoints.jmx.exposure.include=*

When to Use @JmxEndpoint:

  • System administration operations
  • Internal monitoring tools
  • Operations not suitable for HTTP exposure
  • Legacy JMX-based monitoring systems
  • Sensitive operations that shouldn't be web-accessible

Security Benefits:

  • No HTTP exposure - Can't be accessed via web browsers
  • JMX authentication can be configured
  • Network isolation - JMX can be restricted to localhost

@JmxEndpoint is ideal for administrative operations that should only be accessible through JMX management tools, not web interfa

返回列表