druid连接池配置详解配置数据库出现循环依赖问题
问题环境:spring boot 2.0.7、spring cloud Finchley.SR2
当添加⾃动⽣成数据库表的配置(springboot2.0.x 以后就需要显式配置出来)
spring.datasource.schema=classpath:schema.sql
spring.datasource.initialization-mode=always
出现循环依赖问题
***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
servletEndpointRegistrar defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementCon textConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]
↓
healthEndpoint defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]↓
org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration
↓
dataSource
┌─────┐
| scopedTarget.dataSource defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]
↑↓
| org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker
└─────┘
解决⽅法是当前应⽤添加配置
##======添加配置============================================
freshable=none
该⽅式 会导致 @Refresh不⽣效
根据循环依赖出现的提⽰,因该是spring boot2.0.x 版本Hikari默认连接池出现的,
所以⼿动配置数据库连接池durid
<!-- 添加Druid依赖 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
配置⽂件
##druid 连接池配置
pe=com.alibaba.druid.pool.DruidDataSource spring.datasource.druid.initial-size=5
spring.datasource.druid.min-idle=5
spring.datasource.druid.max-active=20
spring.datasource.druid.max-wait=60000
spring.datasource.druid.time-between-eviction-runs-millis=60000 spring.datasource.druid.min-evictable-idle-time-millis=300000 spring.datasource.druid.validation-query=SELECT1FROMDUAL spring.st-on-borrow=false
spring.st-on-return=false
spring.datasource.druid.filter.stat.log-slow-sql=true
spring.datasource.druid.filters=stat,wall
备注
通过测试 2.1.x 以及2.2.x 没有该问题。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论