先上小示例效果图:
再上spring的配置文件:
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
- <!-- 配置sessionFactory -->
- <bean id="sessionFactory"
- class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
- <property name="configLocation">
- <value>classpath:hibernate.cfg.xml</value>
- </property>
- </bean>
- <!-- 配置事务管理器 -->
- <bean id="transactionManager"
- class="org.springframework.orm.hibernate3.HibernateTransactionManager">
- <property name="sessionFactory">
- <ref bean="sessionFactory" />
- </property>
- </bean>
- <!-- 注释驱动事务 -->
- <!--
- <tx:annotation-driven transaction-manager="transactionManager"/>
- -->
- <!-- 配置事务策略 -->
- <tx:advice id="txAdvice" transaction-manager="transactionManager">
- <tx:attributes>
- <tx:method name="create*" propagation="REQUIRED" />
- <tx:method name="update*" propagation="REQUIRED" />
- <tx:method name="delete*" propagation="REQUIRED" />
- <tx:method name="*" propagation="SUPPORTS" read-only="true" />
- </tx:attributes>
- </tx:advice>
- <!-- 事务通知器:哪些类的哪些方法参与事务 -->
- <aop:config>
- <aop:advisor pointcut="execution(* com.qiujy.service.*.*(..))"
- advice-ref="txAdvice" />
- </aop:config>
- <!-- =========================== dao的配置 ================================ -->
- <bean id="genericHibernateDaoImpl"
- class="com.qiujy.dao.hibernate.GenericHibernateDaoImpl"
- abstract="true">
- <property name="sessionFactory" ref="sessionFactory" />
- </bean>
- <bean id="deptDao" class="com.qiujy.dao.hibernate.DeptDaoImpl"
- parent="genericHibernateDaoImpl" />
- <bean id="employeeDao"
- class="com.qiujy.dao.hibernate.EmployeeDaoImpl"
- parent="genericHibernateDaoImpl" />
- <!-- ====================== ServiceFacade的配置 =========================== -->
- <bean id="serviceFacade" class="com.qiujy.service.ServiceFacade">
- <property name="deptDao" ref="deptDao" />
- <property name="employeeDao" ref="employeeDao" />
- </bean>
- <!-- ====================== Struts Action的配置 =========================== -->
- <bean id="baseAction" class="com.qiujy.web.base.BaseAction"
- abstract="true">
- <property name="serviceFacade" ref="serviceFacade" />
- </bean>
- <bean name="/dept" class="com.qiujy.web.dept.DeptAction"
- parent="baseAction" scope="prototype" />
- </beans>
示例源代码将上传到csdn资源库中。呵呵。