182.7. 配置 EntityManagerFactory
强烈建议将 JPA 组件配置为使用特定的 EntityManagerFactory 实例。如果这样做失败,每个 JpaEndpoint 将自动创建自己的 EntityManagerFactory 实例,这最常不是您需要的内容。
例如,您可以实例化引用 myEMFactory 实体管理器工厂的 JPA 组件,如下所示:
<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent"> <property name="entityManagerFactory" ref="myEMFactory"/> </bean>
<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
<property name="entityManagerFactory" ref="myEMFactory"/>
</bean>
在 Camel 2.3 中,JpaComponent 将从 Registry 中自动查找 EntityManagerFactory,这意味着您不需要在上述 JpaComponent 上配置它。只有有不确定性时,您只需要这样做,在这种情况下,Camel 将记录 WARN。