代码之家  ›  专栏  ›  技术社区  ›  LppEdd

Spring-与现有的、不兼容的、名称和类相同的bean定义冲突

  •  1
  • LppEdd  · 技术社区  · 7 年前

    具体的例外情况是:

    Failed to instantiate [org.springframework.context.annotation.AnnotationConfigApplicationContext]: Constructor threw exception;
    nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException:
    Annotation-specified bean name 'myService' for bean class [my.package.ejb.MyService] conflicts with existing, non-compatible bean definition of same name and class [my.package.other.ejb.MyService]
    

    那些 MyService 接口甚至没有注释,它们代表EJB2.0无状态bean。

    我的注释配置如下。

    @Configuration
    @ComponentScan("my.package")
    @MapperScan("my.package")
    public class ApplicationConfiguration {
        @Bean
        public DataSource dataSource() {
            return new JndiDataSourceLookup().getDataSource("...");
        }
    
        @Bean
        public SqlSessionFactoryBean sqlSessionFactory(final DataSource dataSource) {
            final SqlSessionFactoryBean sqlSessionFactory = new SqlSessionFactoryBean();
            sqlSessionFactory.setDataSource(dataSource);
            sqlSessionFactory.setConfigLocation(new ClassPathResource("..."));
            return sqlSessionFactory;
        }
    
        @Bean
        public DataSourceTransactionManager dataSourceTransactionManager(final DataSource dataSource) {
            return new DataSourceTransactionManager(dataSource);
        }
    }
    

    可能与 @MapperScan (来自MyBatis)和 @ComponentScan ?

    例外情况来自 SpringBeanAutowiringInterceptor 我正在使用自动连接EJB3.0字段。

    1 回复  |  直到 7 年前
        1
  •  1
  •   LppEdd    7 年前

    文件 MapperScannerConfigurer 他说:

    此类支持筛选通过指定 标记接口或注释。annotationClass属性 指定要搜索的批注。markerInterface属性 指定要搜索的父接口。如果两个属性都是 指定后,将为匹配以下两种情况的接口添加映射器: 标准 默认情况下,这两个属性为null,因此所有接口 在给定的basePackage中,作为映射器添加 .

    基本上,我将数千个接口映射为bean。不酷!
    伙计们,是我的错。