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