bladex 动态数据源 ‘url‘ attribute is not specified and no embedded datasource could be configured.解决方案

第一次用bladex,使用动态数据源的问题

动态数据源问题

按照正常步骤:

  1. 引入mybatis-plus的动态数据源jar包
  2. 修改yml配置.改为动态数据源配置.
  3. 启动.报错'url' attribute is not specified and no embedded datasource could be configured

原因: bladex默认启动参数关闭了动态数据源(文档又不说…)

解决

全局搜spring.datasource.dynamic.enabled会看到 LauncherServiceImpl这个类中有.点进去,改一下代码.

方式1(不推荐) 简单粗暴,直接将false改为 true

将原来的:

PropsUtil.setProperty(props, "spring.datasource.dynamic.enabled", "false");
PropsUtil.setProperty(props, "spring.datasource.dynamic.enabled", "true");
缺点:

其他模块连接数据库全部得改为动态数据源写法

方式二 动态开启或关闭

改为

if (你们服务名称的字符串.equals(appName)){
			PropsUtil.setProperty(props, "spring.datasource.dynamic.enabled", "false");
}else{
			PropsUtil.setProperty(props, "spring.datasource.dynamic.enabled", "false");
		}

你们服务名称的字符串可以通过启动你们的对应服务,打断点看appName是什么.


版权声明:本文为weixin_42452726原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。