是否有一种明显的方法可以使用Camel Spring DSL中的两个JPA使用者/生产者与两个不同的数据库实例进行通信?我尝试配置两个指向两个持久性单元的EntityManagerFactory实例,但在出错时最终得到以下内容:(
Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: Found 2 beans of type: interface javax.persistence.EntityManagerFactory. Only one bean expected.
骆驼版:2.13.2
答案 0 :(得分:1)
您可能必须创建2个实体管理器工厂,并让它们指向不同的持久性单元。
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="primary" />
</bean>
<bean id="entityManagerFactory2"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="secondary" />
</bean>
然后在设置jpa bean时,可以指定两个不同的来源
<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="jpa2" class="org.apache.camel.component.jpa.JpaComponent">
<property name="entityManagerFactory" ref="entityManagerFactory2" />
<property name="transactionManager" ref="transactionManager" />
</bean>
并使用:
<from uri="jpa://
或
<from uri="jpa2://