本来运行好好的项目,下一次运行却报错了。
报错原因:
Description:
Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
看到报错原因,检查过了数据库源配置的编写,也没有错误。
上一次是可以成功运行的,但是这一次就不能运行了。
找了很多资料,发现有可能是 maven 编译项目出现了问题。
这是最新编译的 class 文件,跟下面对比少了 .yml 等其它的配置文件
说明 resources 文件夹没有被扫描到。
而刚新创建的SpringBoot项目是下面这样的(我更改了配置后缀名 .yml):
解决的办法:
1、在 pom.xml 里面添加扫描配置文件的操作。不过我试过好像不行。
<build>
<resources>
<resource>
<directory>${basedir}/src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.yml</include>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
2、重新生成一个SpringBoot项目,然后将原本项目移过去。
附上 application.yml 的配置内容
mybatis:
mapper-locations: classpath:/mapper/*.xml
type-aliases-package: {此处我填写了存储实体的包}
spring:
main:
allow-bean-definition-overriding: true
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/
{此处填写连接名称}
?allowPublicKeyRetrieval=true
&useAffectedRows=true
&serverTimezone=GMT%2B8
&allowMultiQueries=true
&useUnicode=true
&characterEncoding=UTF-8&useSSL=false
username: root
password: 123456
type: com.alibaba.druid.pool.DruidDataSource
druid:
initial-size: 5
min-idle: 5
max-wait: 60000
max-active: 20
test-on-borrow: false
test-on-return: false
test-while-idle: true
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 30000
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
connection-properties: druid.stat.mergeSql=true
filter:
stat:
merge-sql: true
slow-sql-millis: 5000
use-global-data-source-stat: true
server:
port: 8000
补充:
第二个方法项目小点的话还可以,直接复制黏贴整个项目,不用做太多改动。
不过还是希望不要再发生了。