日期:2014-05-16 浏览次数:20423 次
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="userTransactionName" value="java:comp/UserTransaction"/> </bean> <bean id="transactionAdvisor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager" > <ref local="transactionManager"/> </property> <property name="transactionAttributes"> <props> <prop key="*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- 注册自动代理创建,为业务Bean添加事务拦截器 --> <bean id="BOAutoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="proxyTargetClass" value="true"></property> <property name="beanNames"> <list> <value>*Service</value> </list> </property> <property name="interceptorNames"> <list> <value>trasactionMethodPointcutAdvisor</value> <!-- 注意: 事务拦截器必须包含在业务日志拦截器中,以免事务控制混乱;或者将业务日志的方法recordLog 设置为 PROPAGATION_REQUIRES_NEW 属性 --> </list> </property> </bean> <
<xa-datasource> <jndi-name>XAOracleDS_MAIN</jndi-name> <track-connection-by-tx/> <isSameRM-override-value>false</isSameRM-override-value> <use-java-context>false</use-java-context> <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class> <xa-datasource-property name="URL">jdbc:oracle:thin:@192.168.0.25:1521:DB_SYS</xa-datasource-property> <xa-datasource-property name="User">admin</xa-datasource-property> <xa-datasource-property name="Password">admin</xa-datasource-property> <!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool --> <!--valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name--> <!-- Checks the Oracle error codes and messages for fatal errors --> <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name> <!-- Oracles XA datasource cannot reuse a connection outside a transaction once enlisted in a global transaction and vice-versa --> <no-tx-separate-pools/> <metadata> <type-mapping>Oracle9i</type-mapping> </metadata> </xa-datasource>
public class DAOFactory { /** * 创建DAO类 * @param daoClass * @return * @throws Exception */ public static BaseDAO createDAO(Class daoClass) throws Exception { SessionFactoryManager sessionFactoryManager = (SessionFactoryManager) Be