📑打牌 : da pai ge的个人主页
🌤️个人专栏 : da pai ge的博客专栏
☁️宝剑锋从磨砺出,梅花香自苦寒来
☁️报错信息
springboot2.7.9启动项目报错,应该是数据库连接的问题,导致无法启动。
错误消息如下:
***************************
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).
☁️错误原因
项目写的是json格式却放在properties文件,特别是自己的pom打包是jar的项目,请查看自己的pom.xml文件中的packaging
☁️解决方法
🌤️ 第一种,项目不需要连接数据库,启动报错
解决方法如下:
只要在将@SpringBootApplication修改为@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})就可以启动的时候不需要连接数据库。
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
🌤️第二种,配置yml示例如下
#在application.properties/或者application.yml文件中没有添加数据库配置信息.
spring:
datasource:
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
🌤️第三种,properties文件配置示例如下
spring.datasource.url = jdbc:mysql://localhost:3306/test?setUnicode=true&characterEncoding=utf8

posted on
浙公网安备 33010602011771号