我想配置多數(shù)據(jù)源,添加一個(gè)SQL Server 數(shù)據(jù)庫 ,根據(jù) springboot-mybatis-mutil-datasource 項(xiàng)目的 數(shù)據(jù)源配置文件 的思路,總體代碼如下
@Configuration
@MapperScan(basePackages = {"io.renren.modules.api.dao","io.renren.modules.job.dao","io.renren.modules.oss.dao","io.renren.modules.sys.dao"},sqlSessionFactoryRef = "masterSqlSessionFactory")
public class DruidConfig {
static final String MAPPER_LOCATION = "classpath:mapper/**/*.xml";
@Bean(name = "masterDataSource")
@Primary
public DataSource dataSource(){...}
@Bean(name = "masterSqlSessionFactory")
@Primary
public SqlSessionFactory masterSqlSessionFactory(@Qualifier("masterDataSource") DataSource masterDataSource)throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(masterDataSource);
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
.getResources(DruidConfig.MAPPER_LOCATION));
return sessionFactory.getObject();
}
}
但是遇到如下錯(cuò)誤,無法啟動(dòng)
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'scheduleJobController': Unsatisfied dependency expressed through field 'scheduleJobService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scheduleJobService': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: cronExpression cannot be null
ss.png
就算是注釋掉io.renren.modules.job下@Configuration,@RestController,@RequestMapping
s1.PNG
可以啟動(dòng),但還是無法登錄。
是思路本身有問題,還是有其他配置要做。
注:沒有修改application-dev.yml文件,也沒有配置第二個(gè)數(shù)據(jù)源,只是嘗試一下配置是否可行
s2.PNG