【SpingBoot】报错:Action: Consider the following: If you want an embedded database (H2, HSQL or Derby)..

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

【SpingBoot】报错:Action: Consider the following: If you want an embedded database H2, HSQL or Derby..

  • 问题描述
  • 问题原因
  • 问题解决

问题描述

未进行数据库配置的时候,启动SpringBoot项目出现以下异常

问题原因

       从上面图片的提示也可以看出是因为缺少数据源。众所周知,SpingBoot是自动装配的,好多配置全部都是SpringBoot自己配置好的,我们是不需要手动配置的。但正是由于这个原因,在未配置数据库的情况下,启动项目,会默认加载org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration这个类,而DataSourceAutoConfiguration类使用了@Configuration注解向spring注入了dataSource bean,而我们这里缺少数据源,所以自然会报错。

问题解决

在主启动类上添加以下内容,将扫描数据源的这一自动装配过程给过滤掉

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

主启动类如下:

package com.kuang;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

/**
 * @author potential
 */

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class Spingboot03WebApplication {

    public static void main(String[] args) {
        SpringApplication.run(Spingboot03WebApplication.class, args);
    }

}

再次启动程序就可以了~,

更多推荐

【SpingBoot】报错:Action: Consider the following: If you want an embedded database (

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

发布评论

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

>www.elefans.com

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

  • 104329文章数
  • 26211阅读数
  • 0评论数