SpringBoot启动报错Failed to auto-configure a DataSource 的问题解决!

今天搭建了一个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.添加如下依赖
     
            org.springframework.boot
            spring-boot-starter-web
           
           
               
                    org.springframework.boot
                    spring-boot-starter-tomcat
               

           

       


2.必须要加

            javax.servlet
            javax.servlet-api
       

 

你可能感兴趣的:(springboot)