今天搭建了一个springboot的一个小demo,但是启动的时候报了以下错误。

scription:
Failed to auto-configure a DataSource: 'spring.datasource.url' is not
specified and no embedded datasource could be auto-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.

1.分析:由于在新建项目的时候我添加了mysql组件,但是我将数据源注释掉了,也就是没配数据源。

2.解决方案:

在启动类的@EnableAutoConfiguration

或@SpringBootApplication中添加exclude= {DataSourceAutoConfiguration.class},

排除此类的autoconfig。

即:@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})

3.重新启动以后就可以正常运行。

 

看到网上还有另一个解决方案:

1.添加如下依赖
     <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!-- 移除嵌入式tomcat插件 不移除会启动报错 -->
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

2.必须要加
<dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>

 

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信