spring boot1.5.9和2.0等版本系列配置了Druid数据源之后编译运行的时候提示java.sql.SQLException: url not set的问题

1.控制台里报错提示java.sql.SQLException: url not set
经过断点调试发现yml中配置的Druid的数据源参数都没有正常读取
spring boot1.5.9和2.0等版本系列配置了Druid数据源之后编译运行的时候提示java.sql.SQLException: url not set的问题_第1张图片
2.既然是yml文件等未能成功加载,解决办法如下
spring boot1.5.9和2.0等版本系列配置了Druid数据源之后编译运行的时候提示java.sql.SQLException: url not set的问题_第2张图片
3.在pom.xml中加上这段代码之后即可

<resources>
            <resource>
                <directory>src/main/javadirectory>
                <includes>
                    <include>**/*.ymlinclude>
                    <include>**/*.propertiesinclude>
                    <include>**/*.xmlinclude>
                includes>
                <filtering>falsefiltering>
            resource>
            <resource>
                <directory>src/main/resourcesdirectory>
                <includes>
                    <include>**/*.ymlinclude>
                    <include>**/*.propertiesinclude>
                    <include>**/*.xmlinclude>
                includes>
                <filtering>falsefiltering>
            resource>
        resources>

4.另外我的yml中Druid是这样配置的,仅供参考

spring:
  datasource:
    username: root
    password:
    url: jdbc:mysql://localhost:3306/weixin?useUnicode=true&characterEncoding=UTF-8
    driver-class-name: com.mysql.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

5.我参考的解决博客地址是SpringBoot2.0整合mybatis+Druid报错java.sql.SQLException: url not set

你可能感兴趣的:(spring,boot)