springboot启动报错APPLICATION FAILED TO START

问题启动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
            **/*.properties</include>
            <include>**/*.xml
        
        false
    
    
        src/main/resources
        
            **/*.yml</include>
            <include>**/*.properties
            **/*.xml</include>
        </includes>
        <filtering>false</filtering>
    </resource>
</resources>

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

你可能感兴趣的:(springboot启动异常)