springboot启动报错APPLICATION FAILED TO START

当在SpringBoot项目中添加了mysql-connector-java和mybatis-spring-boot-starter依赖,但未在application.properties中配置数据库连接信息时,会导致启动失败。解决方案包括:正确配置数据库的账号、密码和数据库;确保yml或properties配置文件被正确扫描和加载;或通过在@SpringBootApplication注解中排除DataSourceAutoConfiguration来避免自动配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题启动springboot报错

***************************
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).

原因:

我的原因是添加了这个几个依赖mysql-connector-java mybatis-spring-boot-starter
没有在application.properties的配置文件添加链接mysql的配置信息 ,所以springboot在启动时就会去加载配置文件里mysql的配置信息,没有配置就没有找到所有一出现这个异常

解决方案一

你在修改配置时注意链接mysql的账号和密码和数据库

#spring.datasource.username=root
##spring.datasource.password=root
##spring.datasource.url=jdbc:mysql://127.0.0.1:3306/ssm?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Hongkong
##spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

参考其他解决方案

解决方案二

yml或者properties文件没有被扫描到,需要在pom文件中添加如下.来保证文件都能正常被扫描到并且加载成功.

<!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
<resources>
    <resource>
        <directory>src/main/java</directory>
        <includes>
            <include>**/*.yml</include>
            <include>**/*.properties</include>
            <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
    </resource>
    <resource>
        <directory>src/main/resources</directory>
        <includes>
            <include>**/*.yml</include>
            <include>**/*.properties</include>
            <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
    </resource>
</resources>

解决方案三
排除此类的autoconfig。启动以后就可以正常运行。
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值