我已经使用spring initilzr创建了一个简单的spring boot应用程序。 POM是:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
然后添加一个简单的控制器,该控制器返回字符串“ hello”。端点工作正常,我很高兴,但是我希望在启动应用程序期间将所有已注册的映射记录在日志中。如何实现?
答案 0 :(得分:0)
一种方法是使用 Spring Boot Actuator 来监视应用程序映射。
然后,您将能够使用JMX或HTTP监视数据。
操作方法:
添加此依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2a。对于HTTP:
将此行添加到application.properties
中:
management.endpoints.web.exposure.include=info, health, mappings
然后检查此端点:http://localhost:8080/actuator/mappings(JSON数据)
2b。对于JMX:
将此行添加到application.properties
中:
spring.jmx.enabled=true
然后检查以org.springframework.boot
为前缀的MBean,例如以VisualVM。