报错信息:
***************************
APPLICATION FAILED TO START
***************************
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
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Process finished with exit code 1
错误原因:
Springboot启动时候,需要找到数据库配置,而配置信息没被加载或者配置信息错误
解决方法:
一,模块不需要数据库操作,且没有配置数据库:
1.添加上数据库配置,在application.properties(.yml)文件
2.在启动类上添加属性,默认不去加载数据库配置(如下)
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
二,模块需要数据库操作,需要配置数据库
确认spring.datasource是否配置正常:
1.检查(创建)application.properties或application.yml
2.检查(.properties)(.yml)语法
3.检查application.properties或application.yml位置
确认Mybatis xml里包名和mapper接口包名是否一致
https://www.cnblogs.com/west-iversion/p/12168069.html
确认是不是application.yml配置文件文件没有被扫描
https://www.cnblogs.com/XingXiaoMeng/p/14738060.html
https://blog.youkuaiyun.com/weixin_43158695/article/details/104717561
application.yml配置格式
https://www.cnblogs.com/fanrenren/p/11352642.html
application.yml实例
spring:
thymeleaf:
prefix: classpath:/static/
suffix: .html
datasource:
url: jdbc:mysql://localhost:3306/mmall?useUnicode=true&characterEncoding=UTF-8
username: root
password: mysql
driver-class-name: com.mysql.cj.jdbc.Driver
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
application.properties实例
server.port=8080
server.tomcat.uri-encoding=utf-8
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mmall
spring.datasource.username=root
spring.datasource.password=mysql
spring.thymeleaf.prefix=classpath:/static/