spring监视器actuator配置应用
作者:back2childhood
这篇文章主要介绍了spring监视器actuator配置应用,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
引入依赖
<!-- 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
自定义路径
@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路径只能对管理员访问,注意做权限管理
到此这篇关于spring监视器actuator的文章就介绍到这了,更多相关spring监视器内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!