美文网首页
springboot bug示例4

springboot bug示例4

作者: 凉风拂面秋挽月 | 来源:发表于2019-10-19 22:49 被阅读0次

在引入阿里druid的时候,需要配置相关的druid属性,给它用起来
配置信息如下:
yaml配置:

server:
  port: 8088
spring:
  datasource:
    username: root
    password: 112358
    url: jdbc:mysql://127.0.0.1:3306/testjdbc?serverTimezone=GMT&useUnicode=true&characterEncoding=UTF-8&useSSL=false
    driver-class-name: com.mysql.cj.jdbc.Driver
    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

配置组件注入springboot

@Configuration
public class DruidConfig {
    @ConfigurationProperties(prefix="spring.datasource")
    @Bean
    public DataSource druid() {
        return new DruidDataSource();
    }

}

但在运行时出现如下bug


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]:24:14
Reason: org.apache.log4j.Logger

Action:

Update your application's configuration

经排查发现需要导入log4j,因为yaml中配置了


image.png

在pom文件中配置

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

问题解决。


image.png

相关文章

网友评论

      本文标题:springboot bug示例4

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