0
我正在使用SOA并具有多个persistence.xml(每个组件都依赖于数据库)。我正在使用Spring + JPA。代码示例如下:如何在SOA中配置JPA多持久性单元
在核心:
Code:
public abstract class GenericJpaDAOImpl<T extends BaseEntity> implements GenericJpaDAO<T> {
protected abstract EntityManager getEntityManager();
}
在组件SSO:
Code:
public class UserDAOImpl extends GenericJpaDAOImpl<User> implements UserDAO {
/* Any method specific to UserLogin */
@PersistenceContext(unitName = "sso", type = PersistenceContextType.TRANSACTION)
protected EntityManager entityManager;
@Override
protected EntityManager getEntityManager() {
return this.entityManager;
}
}
的persistence.xml
代码:
<persistence-unit name="sso" transaction-type="RESOURCE_LOCAL">
应用程序XML
Code:
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" >
<property name="dataSource" ref="ssoDataSource" />
<property name="persistenceUnitName" value="sso"></property>
</bean>
<bean id="ssoDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="<URL>"/>
<property name="user" value="<USER>"/>
<property name="password" value="<PASSWORD>"/>
</bean>
Similarlly组件:计费(如上)
我得到了http://forum.springsource.org/showth...sistence-units类似的线程,但这样做的预期行为的工作。在我的情况下如果Billing的应用程序上下文xml被加载,则首先对此组件执行DAO操作工作文件,但SSO组件不起作用。如果需要更多细节,请提出建议并告诉我。
请重新表述您确切的问题,并解释行为是如何预计不会 – Bozho