美文网首页Java 杂谈Java
一个有趣的小错误:Failed to bind properti

一个有趣的小错误:Failed to bind properti

作者: 椰子奶糖 | 来源:发表于2019-08-13 21:58 被阅读71次

今天在玩springboot+druid的时候报了一个错误
如下所示:

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to bind properties under 'spring.datasource' to javax.sql.DataSource:

    Property: spring.datasource.filters
    Value: stat,wall,log4j
    Origin: class path resource [application.yml]:22:14
    Reason: org.apache.log4j.Logger

Action:

Update your application's configuration


Process finished with exit code 1

好久没有遇到写这么清楚的错误日志了(笑),Failed to bind绑定失败,properties配置,在spring.datasource下,好嘛配置出错
Origin: class path resource [application.yml]:22:14,定位配置文件22行

  • application.yml
spring:
  datasource:
#   数据源基本配置
    username: root
    password: 1230
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql:///testcc
    type: com.alibaba.druid.pool.DruidDataSource
#   数据源其他配置
    initialSize: 5
    minIdle: 5
    maxActive: 20
    maxWait: 60000
    timeBetweenEvictionRunsMillis: 60000
    minEvictableIdleTimeMillis: 300000
    validationQuery: SELECT 1 FROM DUAL
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    poolPreparedStatements: true
#   配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
    filters: stat,wall,log4j
    maxPoolPreparedStatementPerConnectionSize: 20
    useGlobalDataSourceStat: true
    connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
server:
  port: 8082

22行是它:filters: stat,wall,log4j,第14个字符开始,继续看: Reason: org.apache.log4j.Logger原因是log4j.Logger,答案明了了,日志错了,这个配置文件基本都是cp过来的一般不会有错,那么猜测没加依赖
于是在pom.xml中加上log4j的依赖

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

成功启动

小结

  • 对于这个错误还是有点小疑问的,在springboot 1.x版本的时候不加log4j的依赖也可以运行(我学的时候用的1.5版本),这次用了2.1版本就要加,看来是它的依赖关系树有点变动。

相关文章

网友评论

    本文标题:一个有趣的小错误:Failed to bind properti

    本文链接:https://www.haomeiwen.com/subject/swsijctx.html