??????????????tx????????????????
1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans xmlns="http://www.springframework.org/schema/beans"
3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4     xmlns:context="http://www.springframework.org/schema/context"
5     xmlns:aop="http://www.springframework.org/schema/aop"
6     xmlns:tx="http://www.springframework.org/schema/tx"
7     xsi:schemaLocation="http://www.springframework.org/schema/beans
8            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
9            http://www.springframework.org/schema/context
10            http://www.springframework.org/schema/context/spring-context-2.5.xsd
11            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
12            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
13     <!-- ????? -->
14     <bean id="dataSource"
15         class="org.apache.commons.dbcp.BasicDataSource"
16         destroy-method="close">
17         <property name="driverClassName" value="com.mysql.jdbc.Driver" />
18         <property name="url"
19             value="jdbc:mysql://192.168.0.244:3306/test?useUnicode=true&amp;characterEncoding=UTF-8" />
20         <property name="username" value="root" />
21         <property name="password" value="root" />
22         <!-- ?????????????? -->
23         <property name="initialSize" value="10" />
24         <!-- ???????? -->
25         <property name="maxActive" value="10" />
26         <!-- ??????.??????????????????????????????????ò?????????????????????????????maxIdle?? -->
27         <property name="maxIdle" value="20" />
28         <!--  С?????.?????е?????????????????????????????Щ???????????????????????? -->
29         <property name="minIdle" value="10" />
30         <property name="defaultAutoCommit" value="true" />
31     </bean>
32     <!-- ?????? -->
33     <bean id="sessionFactory"
34         class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
35         <property name="dataSource" ref="dataSource" />
36         <property name="mappingLocations">
37             <list>
38                 <value>classpath:/com/nms/entity/**/*.hbm.xml</value>
39             </list>
40         </property>
41         <property name="hibernateProperties">
42             <props>
43                 <prop key="hibernate.dialect">
44                     org.hibernate.dialect.MySQL5Dialect
45                 </prop>
46                 <prop key="hibernate.show_sql">true</prop>
47                 <prop key="hibernate.format_sql">true</prop>
48             </props>
49         </property>
50     </bean>
51     <context:annotation-config />
52     <context:component-scan base-package="com.dao" />
53     <!-- ????????????? -->
54     <bean id="transactionManager"
55         class="org.springframework.orm.hibernate3.HibernateTransactionManager">
56         <property name="sessionFactory" ref="sessionFactory" />
57     </bean>
58     <!-- ???????? -->
59     <tx:advice id="txAdvice" transaction-manager="transactionManager">
60         <tx:attributes>
61             <tx:method name="*" propagation="REQUIRED" />
62         </tx:attributes>
63     </tx:advice>
64     <!-- ???????? -->
65     <aop:config>
66         <aop:pointcut id="interceptorPointCuts" expression="execution(* com.dao.*.*(..))" />
67         <aop:advisor advice-ref="txAdvice" pointcut-ref="interceptorPointCuts" />
68     </aop:config>
69 </beans>
??????????????
1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans xmlns="http://www.springframework.org/schema/beans"
3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4     xmlns:context="http://www.springframework.org/schema/context"
5     xmlns:aop="http://www.springframework.org/schema/aop"
6     xmlns:tx="http://www.springframework.org/schema/tx"
7     xsi:schemaLocation="http://www.springframework.org/schema/beans
8            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
9            http://www.springframework.org/schema/context
10            http://www.springframework.org/schema/context/spring-context-2.5.xsd
11            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
12            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
13     <!-- ????? -->
14     <bean id="dataSource"
15         class="org.apache.commons.dbcp.BasicDataSource"
16         destroy-method="close">
17         <property name="driverClassName" value="com.mysql.jdbc.Driver" />
18         <property name="url"
19             value="jdbc:mysql://192.168.0.244:3306/test?useUnicode=true&amp;characterEncoding=UTF-8" />
20         <property name="username" value="root" />
21         <property name="password" value="root" />
22         <!-- ?????????????? -->
23         <property name="initialSize" value="10" />
24         <!-- ???????? -->
25         <property name="maxActive" value="10" />
26         <!-- ??????.??????????????????????????????????ò?????????????????????????????maxIdle?? -->
27         <property name="maxIdle" value="20" />
28         <!--  С?????.?????е?????????????????????????????Щ???????????????????????? -->
29         <property name="minIdle" value="10" />
30         <property name="defaultAutoCommit" value="true" />
31     </bean>
32     <!-- ?????? -->
33     <bean id="sessionFactory"
34         class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
35         <property name="dataSource" ref="dataSource" />
36         <property name="mappingLocations">
37             <list>
38                 <value>classpath:/com/nms/entity/**/*.hbm.xml</value>
39             </list>
40         </property>
41         <property name="hibernateProperties">
42             <props>
43                 <prop key="hibernate.dialect">
44                     org.hibernate.dialect.MySQL5Dialect
45                 </prop>
46                 <prop key="hibernate.show_sql">true</prop>
47                 <prop key="hibernate.format_sql">true</prop>
48             </props>
49         </property>
50     </bean>
51     <context:annotation-config />
52     <!-- ????????·?? -->
53     <context:component-scan base-package="com.dao" />
54     <!-- ???  @Transactional ??? -->
55     <tx:annotation-driven transaction-manager="transactionManager"/>
56     <!-- ????????????? -->
57     <bean id="transactionManager"
58         class="org.springframework.orm.hibernate3.HibernateTransactionManager">
59         <property name="sessionFactory" ref="sessionFactory" />
60     </bean>
61 </beans>
??????????????????????????????д??
1 package com.dao.impl;
2 import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
3 import org.springframework.stereotype.Component;
4 import org.springframework.transaction.annotation.Transactional;
5 import com.dao.UserDao;
6 @Transactional
7 @Component("userDaoAgency")
8 public class UserDaoImpl extends HibernateDaoSupport implements UserDao {
9     /**
10      * ???????????????????
11      */
12     @Transactional(readOnly=true)
13     public void getUser(){
14     }
15 }
??????????????????????????????????????