栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springcloud子模块启动无法配置数据源【Failed to configure a DataSource: ‘url‘ attribute is not specified and ...】

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springcloud子模块启动无法配置数据源【Failed to configure a DataSource: ‘url‘ attribute is not specified and ...】

错误详情:
07:31:04.082 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter - [report,40] - 

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

07:31:04.083 [Thread-1] WARN  c.a.n.c.h.HttpClientBeanHolder - [shutdown,108] - [HttpClientBeanHolder] Start destroying common HttpClient
07:31:04.083 [Thread-1] WARN  c.a.n.c.h.HttpClientBeanHolder - [shutdown,114] - [HttpClientBeanHolder] Destruction of the end
Disconnected from the target VM, address: '127.0.0.1:63119', transport: 'socket'

Process finished with exit code 1
项目环境:

springcloud+Nacos+mybatisPlus

解决方式:

搜索解决方式,有网友说是: 在多模块的maven项目中 springboot没有读到配置文件造成的,所以只用在此模块的最外层pom文件中添加 … 配置, 使用后并不生效.
排查N久后发现, 在nacos中,导入其他项目的完整配置文件后 项目是可以正常启动的,证明是配置文件的问题!!! 删除与当前模块无关的配置文件后,发现, 当前子模块的配置的nacos分组是自己设置的个性化分组,而不是默认的"DEFAULT_GROUP",
在当前项目的 .yml 文件中并没有指定当前使用的分组是个性化分组:

nacos配置:

修改yml文件:

重启,生效!!!

也可以通过注解方式实现:
在启动类上增加注解:

 @SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)

需要注意 : 使用注解还要把allow-bean-definition-overriding的值设为true

spring.main.allow-bean-definition-overriding=true

如果不生效,可以试试手写的:

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(TestApplication.class);
        app.setAllowBeanDefinitionOverriding(true);
        app.run(args);
    }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/769078.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号