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);
    }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值