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);
        }
    
    }
  • 相关阅读:
    Sequelize框架:
    sequelize 测试
    sequelize 用于PostgreSQL,MySQL,SQLite和MSSQL的Node.js / io.js ORM
    node Util 模块
    bluebird的安装配置
    bluebird 开发文档链接
    Node.js的__dirname,__filename,process.cwd(),./的含义
    editplus
    luogu3377 【模板】左偏树(可并堆)
    cf936c Lock Puzzle
  • 原文地址:https://www.cnblogs.com/baby123/p/11889283.html
Copyright © 2011-2022 走看看