最爱老鼠吃大象 2021-11-19 14:30 采纳率: 37.5%
浏览 65
已结题

关于#java#的问题:nested exception is java.lang.IllegalStateException

@Configuration
@MapperScan(basePackages = "com.isafety.project.master.dao", sqlSessionFactoryRef = "masterNewSqlSessionFactory")
public class MasterNewDataSourceConfig {

@Primary // 表示这个数据源是默认数据源, 这个注解必须要加,因为不加的话spring将分不清楚那个为主数据源(默认数据源)
@Bean(name = "masterNewDataSource")
@ConfigurationProperties(prefix = "spring.datasource.master")////读取application.yml中的配置参数映射成为一个对象
public DataSource dataSource() {
    return DataSourceBuilder.create().build();
}

@Primary
@Bean(name = "masterNewSqlSessionFactory")
public MybatisSqlSessionFactoryBean basicSqlSessionFactory(@Qualifier("masterNewDataSource") DataSource basicDataSource) throws Exception {
    MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean();
    factoryBean.setDataSource(basicDataSource);
    factoryBean.setTypeAliasesPackage("com.isafety.project.master.**.domain");
    factoryBean.setVfs(SpringBootVFS.class);
    factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:/mapper/master/*Mapper.xml"));
    return factoryBean;
}

@Primary
@Bean(name = "masterNewSqlSessionTemplate")
public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("masterNewSqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
    return new SqlSessionTemplate(sqlSessionFactory);
}

Application run failed
org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'masterNewDataSource': Could not bind properties to 'DataSource' : prefix=spring.datasource.master, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is java.lang.IllegalStateException: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@38029349 has been closed already

我配置了两个数据源,启动的时候出现这个问题,请帮我分析一下这是什么问题

  • 写回答

1条回答 默认 最新

  • a1767028198 2021-11-19 14:53
    关注

    这就需要自己debug了,ConfigurationPropertiesBindingPostProcessor这个类实现的绑定过程

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 3月1日
  • 已采纳回答 2月21日
  • 创建了问题 11月19日

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办