<beans
<!--spring数据源配置--> <bean id="DataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://localhost:3306/test</value> </property> <property name="username"> <value>root</value> </property> <property name="password"> <value>mysql</value> </property> </bean>
<!--sessionFactory 配置hibernate 映射--> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="DataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> </props> </property> <property name="mappingResources"> <list> <value>com/hibernate/ormXml/Customers.hbm.xml</value> <value> com/hibernate/ormXml/Customeraddress.hbm.xml </value> </list> </property>
<!--DAO层引用sessionFactory--> </bean> <bean id="CustomersDAO" class="com.hibernate.dao.CustomersDAO"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <bean id="CustomeraddressDAO" class="com.hibernate.dao.CustomeraddressDAO"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean>
<!--事务配置开始-->
<!--hibernate transaction [start]-->
<!-- declare transaction hibernate [start] (事务分二种,以下为声明式事务) --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="sessionFactory"/> </property> </bean> <bean id="exampler1_service" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"> <ref local="transactionManager"/> </property> <property name="target"> <ref local="CustomersDAO"/> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly </prop> <prop key="set*"> PROPAGATION_REQUIRED,readOnly </prop> <prop key="save"> PROPAGATION_REQUIRED,readOnly </prop> </props> </property> </bean><!--hibernate transaction [end]--> <!-- declare transaction hibernate [end] -->
<!-- programing transaction hibernate (编程式事务) [start] --> <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate"> <property name="transactionManager"> <ref local="transactionManager"/> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="sessionFactory"/> </property> </bean> <!-- programing transaction hibernate [end] -->
<!--其它事务配置-->
<!-- JDBC TransactionManager [start]--> <bean id="transactionManager_jdbc" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource"> <ref local="dataSource_jdbc"/> </property> </bean> <bean id="dataSource_jdbc" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <value>java:/MySqlDs</value> </property> </bean> <!--JDBC TransactionManager [end] --> <!-- JDO TransactionManager [start]--> <bean id="transactionManager_jdo" class="org.springframework.orm.jdo.JdoTransactionManager"> <property name="persistenceManagerFactory"> <ref local="dataSource_jdbc"/> </property> </bean> <!-- JDO TransactionManager [end] --> <!-- JTA TransactionManager [start]--> <bean id="transactionManager_jta" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="userTransactionName"> <value>java:comp/UserTransaction</value> </property> </bean> <!-- JTA TransactionManager [end] -->
<!--事务配置结束-->