Spring Boot报 Action: Consider the following: If you want an embedded database (H2, HSQL or Derby)...

编程知识 更新时间:2023-05-02 05:27:30

异常:

        Spring Boot项目启动不成功报


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

首先检查生成的 target 文件中是否包含了你在resources 中编写的的配置文件 application.yml等等,若没有包含,而你的项目中却需要调用就会报此异常,你可以添加以下代码至pom.xml中。里面的.properties可以视你的配置文件后缀名所定。

  <build>
    <!--idea  识别.xml  指定资源的位置-->
    <resources>
      <resource>
        <directory>src/main/java</directory><!--所在目录-->
        <includes>
          <include>**/*.properties</include>
          <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
      </resource>
      <resource>
        <directory>src/main/resources</directory><!--所在目录-->
        <includes>
          <include>**/*.yml</include>
          <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
      </resource>
    </resources>
  </build>

再者还有可能是因为spring boot 会默认加载org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration这个类,而DataSourceAutoConfiguration类使用了@Configuration注解向spring注入了dataSource bean,又因为项目(eureka-server模块和短信模块)中并没有关于dataSource相关的配置信息,所以当spring创建dataSource bean时因缺少相关的信息就会报错。

解决方法就是在启动类头上加行代码。

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class SpringBootApplication {
 
    public static void main(String[] args) {
        SpringApplication.run(SpringBootApplication.class, args);
    }
}

更多推荐

Spring Boot报 Action: Consider the following: If you want an embedded database (H

本文发布于:2023-04-26 06:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/39d5c691251172f400604cbce7b82608.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Action   embedded   Spring   Boot   HSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 104449文章数
  • 26214阅读数
  • 0评论数