Failed to configure a DataSource

2022-11-15 15:55:22 浏览数 (1)

1.项目打包出现错误即target有把配置文件打包进去

启动类头部声明@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}),但是这样会排除掉我自己的数据库配置,

检查了很多地方都没发现问题在哪里,最后自己猜想不论怎么修改application.yml文件,都不生效,是不是因为这个配置文件就没有被加载到?

带着这个想法我就去网上搜了一下问题,有个问题看到了target目录的作用,就去想了一下是不是application.yml文件没有被编译出来到target目录下

2. 修改该项目的 pom.xml 文件,在相应的位置添加了以下的内容

代码语言:javascript复制
<?xml version="1.0" encoding="UTF-8"?>
<project ......>
   <build>
      <resources>
         <resource>
            <directory>src/main/java</directory>
            <includes>
               <include>**/*.xml</include>
            </includes>
         </resource>
         <resource>
            <directory>src/main/resources</directory>
            <includes>
               <include>**/*.xml</include>
               <include>**/*.properties</include>
               <include>**.*.yml</include>
               <include>**.*.yaml</include>
            </includes>
         </resource>
      </resources>
   </build>
</project>

3.mysql 数据连接信息 

spring.datasource.driver-class-name = com.mysql.jdbc.Driver spring.datasource.url = jdbc:mysql://localhost/etc_systemuseUnicode=true&characterEncoding=utf8&useSSL=false spring.datasource.username = root spring.datasource.password = root

0 人点赞