第一次用bladex,使用动态数据源的问题
动态数据源问题
按照正常步骤:
- 引入mybatis-plus的动态数据源jar包
- 修改yml配置.改为动态数据源配置.
- 启动.报错
'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
是什么.