Springboot配置druid报错Failed to bind properties under 'spring.datasource' to javax.sql.DataSource
造成原因:springboot在使用druid时,引入了druid的数据源,在配置文件application.properties中配置了相关配置后,还配置了druid的过滤器,如果过滤器中有log4j,一定要在pom文件中加入log4j的依赖,否则建议移除过滤器中的log4j 配置
报错配置:
# 配置sql 注入方式
spring.datasource.druid.filters=stat, log4j
解决办法,添加log4j 配置依赖
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
另外一种解决办法:移除过滤器中的log4j 配置
# 配置sql 注入方式
spring.datasource.druid.filters=stat