我想配置多數(shù)據(jù)源镜雨,添加一個SQL Server 數(shù)據(jù)庫 荚坞,根據(jù) springboot-mybatis-mutil-datasource 項目的 數(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();
}
}
但是遇到如下錯誤懒鉴,無法啟動
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
就算是注釋掉io.renren.modules.job下@Configuration临谱,@RestController,@RequestMapping
可以啟動城豁,但還是無法登錄抄课。
是思路本身有問題,還是有其他配置要做跟磨。
注:沒有修改application-dev.yml文件抵拘,也沒有配置第二個數(shù)據(jù)源,只是嘗試一下配置是否可行