fix(): 修复空指针异常问题
parent
d81b53910e
commit
0b97b1e2ed
|
@ -11,6 +11,7 @@ import com.muyu.cloud.common.saas.domain.model.EntInfo;
|
|||
import com.muyu.cloud.common.saas.exception.SaaSException;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.SpringUtils;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.remote.RemoteUserService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
@ -78,7 +79,7 @@ public class ManyDataSource implements ApplicationRunner {
|
|||
)
|
||||
.toList();
|
||||
}else {
|
||||
log.error("远调数据源错误,远调数据为:{}", JSON.toJSONString(data));
|
||||
log.error("远调数据源异常,异常信息:{}", JSON.toJSONString(entListResult.getMsg()));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -91,6 +92,10 @@ public class ManyDataSource implements ApplicationRunner {
|
|||
*/
|
||||
@Bean
|
||||
public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) {
|
||||
List<EntInfo> entInfoList = dataSourceInfoList();
|
||||
if(StringUtils.isEmpty(entInfoList)){
|
||||
throw new SaaSException("数据源信息列表为空或为null");
|
||||
}
|
||||
Map<Object, Object> dataSourceMap = dataSourceInfoList().stream()
|
||||
.map(entInfo -> DataSourceInfo.hostAndPortBuild(
|
||||
entInfo.getEntCode(),
|
||||
|
@ -109,19 +114,4 @@ public class ManyDataSource implements ApplicationRunner {
|
|||
dynamicDataSource.setDefineTargetDataSources(dataSourceMap);
|
||||
return dynamicDataSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 SqlSessionFactory Bean,用于 MyBatis 数据库操作。
|
||||
* 该方法接收动态数据源并配置 SqlSessionFactory,返回
|
||||
* 用于与数据库交互的 SqlSessionFactory 实例。
|
||||
* @param dataSource 动态数据源
|
||||
* @return 配置好的 SqlSessionFactory 实例
|
||||
* @throws Exception 可能抛出的异常
|
||||
*/
|
||||
@Bean
|
||||
public SqlSessionFactory sqlSessionFactory(DynamicDataSource dataSource) throws Exception {
|
||||
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
|
||||
sessionFactory.setDataSource(dataSource);
|
||||
return sessionFactory.getObject();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue