【发布时间】:2021-08-07 08:05:15
【问题描述】:
我有一个遗留的 spring 模块,它具有从 dataSource 到 transactionManager 的数据 bean 定义(基于 C3P0 和 Hibernate)。我想在 Spring Boot 应用程序中重用所有这些 bean 定义。 Spring boot 构建文件默认从 initializr 生成。在运行时,我遇到了以下错误:
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Generic.class]: @Bean definition illegally overridden by existing bean definition: Generic bean: class [com.mchange.v2.c3p0.ComboPooledDataSource]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=close; defined in class path resource*
dataSource 是 data-beans.xml 中的一个 bean。 我已经使用 @Configuration 导入了 xml bean 定义:
@ImportResource({"classpath:data-beans.xml"})
public class XmlConfig {
}
【问题讨论】:
-
如果您要迁移到 Boot,您可能可以从逐步删除 Boot 为其提供自动模板的手写定义开始。
标签: java spring spring-boot