`
阅读更多

Failed to configure a DataSource: 'url' attribute is not specified and no embedd

Reason: Failed to determine a suitable driver class

 

================================

©Copyright 蕃薯耀 2020-04-24

 

https://www.iteye.com/blog/user/fanshuyao

 

一、问题描述

复制代码
***************************
APPLICATION FAILED TO START
***************************

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).
复制代码

 

原因就是springboot找到数据源的配置,但配置是有的,而且是正确的,为什么提示这个错误?

 

二、解决方案:

其实这个问题是包(package)路径的问题

在Springboot中,会自动扫描主启动类(@SpringBootApplication)包及所有子包

复制代码
package com.datasource;

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

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class Demo1Application {

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

}
复制代码

 

当你修改了主启动类的包名时,如将com.datasource修改成com.ds,但之前的子包没有同时修改,就会出现获取不到url的问题。因为主主启动类自动扫描com.ds及其所有子包,但此时是没有子包的。

一个简单的现象就是:当类被spring纳入管理时,类右上角是有一个“S”字母的,当你修改包名后,以前受spring管理的bean就失效,导致springboot识别不了。

 

解决方法:

方法一:

保证类路径一致(尽量不要手动修改主启动类,如果命名不合适需要更改,就要同时修改,类路径保持一致。)。

 

方法二:

在主启动类,使用@Import或@ComponentScan,引入包路径不一致但需要受到springboot管理的类。

 

 

================================

©Copyright 蕃薯耀 2020-04-24

 

https://www.iteye.com/blog/user/fanshuyao

 

 

 

分享到:
评论

相关推荐

    haxmfori7.rar

    在描述中提到的“Failed to configure driver: unknown error. Failed to open driver”是一个常见的错误提示,意味着在安装或配置HAXM时遇到了问题。 Intel HAXM依赖于计算机的硬件虚拟化功能,尤其是CPU的虚拟化...

    Linphone编译错误及解决方法

    4. failed to with "configure: error: "Could not find libreadline headers or library" 错误原因:缺少libreadline头文件或库文件。 解决方法:apt-get install libreadline5-dev 5. fail with "checking for ...

    svn安装过程中遇到错误需要的文件包

    错误 configure: error: could not find library containing RSA_new: 错误 configure: error: no XML parser was found: expat or libxml 2.x required 解放方法: ...

    sqlite3文件(sqlite3:not found 解决方法)

    sqlite3文件(用于解决安卓真机中sqlite3:not found的错误) http://blog.csdn.net/hust_twj/article/details/52212558

    device-mapper.1.02.28.tgz

    在编译parted-3.2时,报错:configure: error: libdevmapper could not be found,找到device-mapper.1.02.28,并下了下来。 这个源码藏得有点深,分享出来给大家

    CentOS下编译php时的一些典型错误及解决办法.

    11. configure: error: Cannot find MySQL header files under /usr.Note that the MySQL client library is not bundled anymore! 解决方法: yum install mysql-devel 此错误是由于缺少 mysql-devel 库文件所...

    gmp 5.0.4 安装GCC必需文件

    There is no practical limit to the precision except the ones implied by the available memory in the machine GMP runs on. GMP has a rich set of functions, and the functions have a regular interface.

    PHP编译configure时常见错误的总结

    7. **错误:configure: error: mod_deflate has been requested but can not be built due to prerequisite failures** 解决方案:在CentOS上,安装`zlib-devel`和`openssl-devel`,命令分别是`yum -y install zlib...

    libmount-2.32.tar.gz

    然而,当我们尝试编译和安装这个版本时,可能会遇到“configure: error: *** Could not find libmount”这样的错误提示,这通常是由于系统环境配置不完整或者依赖关系未满足所导致的。 首先,我们要明白“configure...

    Linux 开发板移植gdb

    开发板没有gdb,写程序老出错而且找不到问题在哪里。于是痛定思痛,决定移植一个gdb。 交叉编译器:arm-none-linux-gnueabi ...(3)./configure –host=arm-none-linux-gnueabi –prefix=$PWD/install –wi

    gcc-4.9.4安装包

    在编译安装软件的时候,发现错误configure: error: *** A compiler with support for C++11 language features is required. 要支持C++11,必须升级到gcc4.7以上。

    gcc_4.9.4_gcc+gmp+mpfr+mpc.tar.gz

    编译安装软件的时候,发现错误configure: error: *** A compiler with support for C++11 language features is required. 原来是gcc版本太低了,我的版本是gcc version 4.6.3 想要支持C++11,必须升级到gcc4.8...

    Android JNI 断点调试C++

    # Provides a relative path to your source file(s). src/main/cpp/HelloNDK.cpp ) ``` 2. 在Android Studio中,启用调试模式,选择目标设备或模拟器,确保它支持JNI调试。 调试步骤: 1. 在C++代码中设置断点...

    php源代码安装常见错误与解决办法分享

    14. **错误:configure: error: mod_deflate has been requested but can not be built due to prerequisite failures** 解决:缺少zlib和openssl的开发库,执行`yum -y install zlib-devel openssl-devel`。 15. ...

    计算机网络第六版答案

    14. If the two ISPs do not peer with each other, then when they send traffic to each other they have to send the traffic through a provider ISP (intermediary), to which they have to pay for carrying ...

    proj-6.2.0.zip

    proj-6.2.0 cmake windows vs2015编译包括dll lib cct.lib cs2cs.lib geod.lib geodtest.lib gie.lib gie_self_tests.lib gtest.lib pj_phi2_test.lib proj.lib proj_6_2.lib proj_angular_io_test.lib proj_...

    FFmpeg-安装过程

    ffmpeg -i audio1.mp3 -i audio2.mp3 -filter_complex "[0:a][1:a]amix=inputs=2[a]" -map "[a]" output.mp3 ``` FFmpeg的安装和使用涉及多方面知识,包括编译原理、多媒体处理、编码标准等。熟练掌握FFmpeg能极...

    suse系统ssh升级压缩包.tar

    本升级包中包含openssh-8.1p1.tar.gz openssl-1.1.1b.tar.gz zlib-1.2.11.tar.gz等3个源码资源包。

    编译PHP报错configure error Cannot find libmysqlclient under usr的解决方法

    在PHP的mysqli扩展中,如果遇到“configure: error: wrong mysql library version or lib not found”错误,可能还需要在mysqli扩展目录下进行以下操作: 1. **切换到mysqli扩展目录**:`cd /usr/local/src/...

Global site tag (gtag.js) - Google Analytics