具体的异常(exception)是:
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
接口(interface)甚至没有注释,它们代表 EJB 2.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
不兼容?
异常来 self 用于 Autowiring EJB 3.0 字段的 SpringBeanAutowiringInterceptor
。
最佳答案
MapperScannerConfigurer 的文档说:
This class supports filtering the mappers created by either specifying a marker interface or an annotation. The annotationClass property specifies an annotation to search for. The markerInterface property specifies a parent interface to search for. If both properties are specified, mappers are added for interfaces that match either criteria. By default, these two properties are null, so all interfaces in the given basePackage are added as mappers.
基本上,我将数千个接口(interface)映射为 bean。不酷!
伙计们,我的错。
关于java - Spring - 与现有的、不兼容的同名和类的 bean 定义冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50545300/