Spring添加事物支持 applicationContext.xml配置文件

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans
 3     xmlns="http://www.springframework.org/schema/beans"
 4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5     xmlns:p="http://www.springframework.org/schema/p"
 6     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
 7 
 8 
 9     <bean id="dataSource"
10         class="org.apache.commons.dbcp.BasicDataSource">
11         <property name="driverClassName"
12             value="com.mysql.jdbc.Driver">
13         </property>
14         <property name="url" value="jdbc:mysql://localhost:3306/db"></property>
15         <property name="username" value="root"></property> 
16         <property name="password" value="123"></property>
17     </bean>
18     <bean id="sessionFactory"
19         class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
20         <property name="dataSource">
21             <ref bean="dataSource" />
22         </property>
23         <property name="hibernateProperties">
24             <props>
25                 <prop key="hibernate.dialect">
26                     org.hibernate.dialect.MySQLDialect
27                 </prop>
28             </props>
29         </property>
30         <property name="mappingResources">
31             <list>
32                 <value>com/proj/entity/Userinfo.hbm.xml</value>
33                 <value>com/proj/entity/Message.hbm.xml</value></list>
34         </property></bean>
35         
36         
37         <bean id="userDao" class="com.proj.dao.UserDaoImpl" >
38         <property name="sessionFactory" ref="sessionFactory"></property>
39         </bean>
40         <bean id="stuBizTarget" class="com.proj.biz.UserBizImpl">
41         <property name="userDao" ref="userDao"></property>
42         </bean>
43     
44         <!--spring 中配置事物完整配置文件 -->
45         <!-- 创建一个事物 -->
46     <bean id="trans"
47         class="org.springframework.orm.hibernate3.HibernateTransactionManager">
48         <property name="sessionFactory" ref="sessionFactory" />
49     </bean>
50     <!-- 使用事物 -->
51     <bean id="stuBiz"
52         class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
53         <property name="proxyInterfaces"><!-- 代理接口 -->
54             <list>
55                 <value>com.proj.biz.UserBiz</value>
56             </list>
57         </property>
58         <property name="target" ref="stuBizTarget" /><!-- 接口实现类目标 -->
59         <property name="transactionManager" ref="trans"></property><!-- 事物管理  -->
60         <property name="transactionAttributes"><!-- 类中所用方法都使用事物  不适用调整key值 -->
61             <props>
62                 <prop key="*">PROPAGATION_REQUIRED</prop>
63             </props>
64         </property>
65         </bean>
66        <!-- Action配置文件 -->
67         <bean id="userAction" class="com.proj.action.UserAction">
68         <property name="userBiz" ref="stuBiz"></property><!-- 使用事物的stuBiz -->
69         </bean>
70         </beans>

 

posted @ 2012-09-24 09:25  小伙、不一般  阅读(412)  评论(0编辑  收藏  举报