<!-- DAO -->
<bean id="UserDAO" class="com.ljj.dao.UserDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="DeptDAO" class="com.ljj.dao.DeptDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- Service -->
<bean id="userSer" class="com.ljj.service.impl.UserServiceImpl">
<property name="userdao" ref="UserDAO"></property>
<property name="deptdao" ref="DeptDAO"></property>
</bean>
<!-- 配置userSer中的事务 -->
<!-- 事务配置 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!-- 第一种 -->
<bean id="userDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="tx">
<ref bean="txManager"/>
</property>
<property name="proxyTargetClass">
<value>false</value>
</property>
<property name="proxyInterfaces">
<ref bean="userSer"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<!-- 第二种 利用继承-->
<bean id="txBase" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
lazy-init="true" abstract="true">
<property name="tx">
<ref bean="txManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id = "userDAOProxy" parent="txBase">
<property name="target">
<ref bean="userSer"/>
</property>
</bean>
<!-- 第三种 BeanNameAutoProxyCreator -->
<bean id="txInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="tx">
<ref bean="txManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key=""></prop>
</props>
</property>
</bean>
<bean id="autoProxy" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanName">
<list>
<value>userSer</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>txInterceptor</value>
</list>
</property>
</bean>
<!-- 第四种 自动创建 -->
<bean id="txInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="tx">
<ref bean="txManager"/>
</property>
</bean>
<bean id="autoProxy" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanName">
<list>
<value>*Service</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>txInterceptor</value>
</list>
</property>
</bean>
<!-- 用正则表达式 -->
<bean id="regExp" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice">
<ref bean="txInterceptor"/>
</property>
<property name="pattern">
<value>.*</value>
</property>
</bean>