zoukankan      html  css  js  c++  java
  • spring boot 启动遇到报错:Failed to configure a DataSource

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

    出错的原因:

      在pom.xml中引入了 mybatis-spring-boot-starter,会自动加载org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration类

      DataSourceAutoConfiguration类使用了@Configuration注解向spring注入了DataSource bean

      因此如果没有配置DataSource,就会报错

    解决的方法:

      修改启动类,添加 @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}),阻止spring 自动注入DataSource

    package com.abc.robin.backup;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
    
    @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
    @SpringBootApplication
    public class RobinBackupApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(RobinBackupApplication.class, args);
        }
    
    }
  • 相关阅读:
    P3803 【模板】多项式乘法(FFT)
    P2264 情书 Trie匹配
    CF877E Danil and a Part-time Job 线段树维护dfs序
    P3810 【模板】三维偏序(陌上花开)
    LOJ #6282. 数列分块入门 6
    LOJ #6281. 数列分块入门 5
    LOJ #6280. 数列分块入门 4
    LOJ #6279. 数列分块入门 3
    LOJ #6278. 数列分块入门 2
    LOJ #6277. 数列分块入门 1
  • 原文地址:https://www.cnblogs.com/baby123/p/11889283.html
Copyright © 2011-2022 走看看