java大佬们有遇到这种错误没

117 阅读1分钟

错误信息

Description:

The dependencies of some of the beans in the application context form a cycle:

   indexController (field private com.byker.modules.info.service.IndexService com.byker.modules.info.controller.IndexController.indexService)
      ↓
   indexService (field protected com.baomidou.mybatisplus.core.mapper.BaseMapper com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.baseMapper)
      ↓
   indexDao defined in file [F:\end plan\byker\byker_admin\target\classes\com\byker\modules\info\dao\IndexDao.class]
      ↓
   sqlSessionFactory defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]
┌─────┐
|  dataSource defined in class path resource [com/byker/datasources/DynamicDataSourceConfig.class]
↑     ↓
|  firstDataSource defined in class path resource [com/byker/datasources/DynamicDataSourceConfig.class]
↑     ↓
|  org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker
└─────┘

多数据源配置

/**
 * 配置多数据源
 */
@Configuration
public class DynamicDataSourceConfig {

  @Bean
  @ConfigurationProperties("spring.datasource.first")
  public DataSource firstDataSource() {
    return DataSourceBuilder.create().build();
  }


  @Bean
  @ConfigurationProperties("spring.datasource.second")
  public DataSource secondDataSource() {
    return DataSourceBuilder.create().type(HikariDataSource.class).build();
  }


  @Bean
  @Primary
  public DynamicDataSource dataSource(DataSource firstDataSource, DataSource secondDataSource) {
    Map<Object, Object> targetDataSources = new HashMap<>(2);
    targetDataSources.put(DataSourceNames.FIRST, firstDataSource);
    targetDataSources.put(DataSourceNames.SECOND, secondDataSource);
    return new DynamicDataSource(firstDataSource, targetDataSources);
  }
}
/**
 * 动态数据源
 */
public class DynamicDataSource extends AbstractRoutingDataSource {
  private static final ThreadLocal<String> contextHolder = new ThreadLocal<>();

  public DynamicDataSource(DataSource defaultTargetDataSource, Map<Object, Object> targetDataSources) {
    super.setDefaultTargetDataSource(defaultTargetDataSource);
    super.setTargetDataSources(targetDataSources);
    super.afterPropertiesSet();
  }

  @Override
  protected Object determineCurrentLookupKey() {
    return getDataSource();
  }

  public static void setDataSource(String dataSource) {
    contextHolder.set(dataSource);
  }

  public static String getDataSource() {
    return contextHolder.get();
  }

  public static void clearDataSource() {
    contextHolder.remove();
  }

}

项目目录

image.png

遇到好几次这种情况了,没找到原因,哎,有哪位打来知道这是啥问题不