引入依赖
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>3.1.0</version>
</dependency>
配置
# actuator
# 将所有路径都加入监视
management.endpoints.web.exposure.include=*
# 将某几个路径取消监控
management.endpoints.web.exposure.exclude=info,caches
应用
自带的路径
localhost:8080/mycommunity/actuator/health
localhost:8080/mycommunity/actuator/beans
localhost:8080/mycommunity/actuator/loggers
文章来源:https://www.toymoban.com/news/detail-534079.html
自定义路径
@Component
@Endpoint(id = "database")
public class DatabaseEndpoint {
private static final Logger logger = LoggerFactory.getLogger(DatabaseEndpoint.class);
@Autowired
private DataSource dataSource;
// readOperation means this method can only be accessed by get request
// writeOperation means this method can only be accessed by post request
@ReadOperation
public String checkConnection(){
try(
Connection connection = dataSource.getConnection();
) {
return CommunityUtil.getJSONString(0,"success");
} catch (SQLException e) {
e.printStackTrace();
logger.error("failed");
}
return CommunityUtil.getJSONString(1, "failed");
}
}
访问浏览器:localhost:8080/mycommunity/actuator/database
注意actuator路径只能对管理员访问,注意做权限管理文章来源地址https://www.toymoban.com/news/detail-534079.html
到了这里,关于spring监视器actuator的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!