spring-boot - Springboot:显示注册的映射
问题描述
我使用 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'的简单控制器。端点工作,我很高兴,但我希望在启动应用程序期间记录所有已注册的映射。如何做到这一点?
解决方案
一种方法是使用Spring Boot Actuator来监视应用程序映射。
然后,您将能够使用 JMX 或 HTTP 监视数据。
如何 :
- 添加 Spring Boot 执行器(请参阅https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-enabling)
添加此依赖项:
<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
然后检查以 为前缀的 MBean ,例如org.springframework.boot
使用VisualVM 。
推荐阅读
- hyperlink - I want to Stop Redirect of specific link in my blogger post
- django - Django 脏字段——我们可以访问之前和之后的状态吗?
- reactjs - NextJS - 使用 Webpack Externals 更快地构建
- android - 你如何在 android studio avd 中激活文本到语音
- java - 我想使用 recyclerview 将我的画廊加载到片段中。但它不起作用
- python - 如何为 Django 过滤子对象的父字段
- java - Java 13 迁移后无法创建请求的服务 [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
- javascript - firefox 阻止 ctrl + shift + p 快捷方式打开私人浏览器窗口
- php - 将 if else 语句的“echo”结果保存到变量中?
- c++ - 我可以在不同的重定向上混合 new 和 malloc 吗?