【发布时间】:2014-08-04 15:34:06
【问题描述】:
我有两个数据库配置 javaconfig 类 - 一个用于 JPA 目的,带有 transactionManager() 和 entityManagerFactory() @Bean 方法,另一个配置类用于基于非 JPA JDBCTemplate 的查询提交以访问该数据库中的数据。总体思路是使用 JDBCTemplate 读取数据并在转换后将数据持久化到基于 JPA 的数据源中。我正在使用 Spring Boot 来启用自动配置。我的测试失败了:
java.lang.IllegalArgumentException: Not an managed type:
我的build.gradle 中有spring-boot-starter-jdbc 和spring-boot-starter-data-jpa。我的直觉是这两个数据源相互冲突。对于我前面提到的两个用例(一个用于 JPA,另一个用于 JDBCTemplate),如何强制使用这些数据源?
详情(在 Dave 回复后添加):
我的服务类已用 @Service 注释,我的存储库类已用 @Repository 注释。服务使用使用 @Autowired 的存储库对象,尽管有些服务是基于 JDBCTemplate 的数据检索。
我的环境更复杂的描述如下(逻辑上):JDBCTemplate(DataSource(Database(DB2)))-->Spring Batch Item Reader;Processors; Writer --> Service(Repository(JPADataSource(Database(H2))))。 Spring 批处理项目处理器使用服务连接到两个数据库。对于 Spring Batch,我使用 H2 Job repo 数据库(远程)来保存作业执行详细信息。这有意义吗?对于 Spring 批处理,我使用的是 de.codecentric:spring-boot-starter-batch-web:1.0.0.RELEASE。经过entityManagerFactory bean not found 错误后,我想控制上述组件的接线。
【问题讨论】:
标签: spring-batch spring-data-jpa spring-jdbc spring-boot