使用Spring Boot Actuator的一些坑

1、应用启动时报数据源加载循环引用的错


image.png
2019-03-19 15:37:26,501  main  WARN (Jdk14Logger.java)- Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'syncUserBalacneServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'balanceService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'balanceMapper' defined in file [/Users/qiying/Documents/projects/java/yunpian-attila-account-service/yunpian-attila-account-service-impl/target/classes/com/yunpian/attila/account/spring/cloud/application/mapper/BalanceMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'scopedTarget.dataSource': Requested bean is currently in creation: Is there an unresolvable circular reference?

解决:在yml文件中添加配置

spring:
   cloud:
      refresh:
        refreshable: none

2、想通过actuator的shutdown来停止应用,按照网上的配置endpoints.shutdown.enabled=true
配置之后请求/shutdown 报404的错。查阅文档https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html#production-ready-endpoints-exposing-endpoints 除了info和health端点,其他端点Actuator对web请求是默认不暴露的,所以需要手动配置

management:
  endpoints:
    web:
      exposure:
        # 暴露的端点
        include: shutdown 
  endpoint:
    #开启shutdown
    shutdown:
      enabled: true

然后访问/shutdown就可以成功停止应用了

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。