Spring - 与现有的、不兼容的同名 bean 定义和 class 冲突
Spring - conflicts with existing, non-compatible bean definition of same name and class
具体例外是:
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
接口甚至没有注释,它们代表 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
不兼容?
异常来自 SpringBeanAutowiringInterceptor
我用来自动装配 EJB 3.0 字段。
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.
基本上我将数千个接口映射为 bean。不酷!
伙计们,我的错。
具体例外是:
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
接口甚至没有注释,它们代表 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
不兼容?
异常来自 SpringBeanAutowiringInterceptor
我用来自动装配 EJB 3.0 字段。
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.
基本上我将数千个接口映射为 bean。不酷!
伙计们,我的错。