web.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 5 http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 6 <display-name></display-name> 7 8 <context-param> 9 <param-name>contextConfigLocation</param-name> 10 <param-value>classpath:applicationContext.xml</param-value> 11 </context-param> 12 13 <listener> 14 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 15 </listener> 16 17 <filter> 18 <filter-name>OpenSessionInViewFilter</filter-name> 19 <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> 20 </filter> 21 <filter-mapping> 22 <filter-name>OpenSessionInViewFilter</filter-name> 23 <url-pattern>/*</url-pattern> 24 </filter-mapping> 25 26 <filter> 27 <filter-name>struts2</filter-name> 28 <filter-class> 29 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 30 </filter-class> 31 </filter> 32 <filter-mapping> 33 <filter-name>struts2</filter-name> 34 <url-pattern>/*</url-pattern> 35 </filter-mapping> 36 37 <welcome-file-list> 38 <welcome-file>login.jsp</welcome-file> 39 </welcome-file-list> 40 </web-app>
applicationContext.xml
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" xmlns:p="http://www.springframework.org/schema/p" 4 xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" 5 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 6 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 7 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> 8 9 <!-- sessionFactory --> 10 <bean id="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 11 <property name="configLocation" value="classpath:hibernate.cfg.xml" /> 12 </bean> 13 14 <bean id="userDao" class="dao.impl.UserDaoImpl" p:sessionFactory-ref="sessionFactory" /> 15 16 <bean id="userBiz" class="biz.impl.UserBizImpl" p:userDao-ref="userDao" /> 17 18 <bean id="userAction" class="action.UserAction" p:userBiz-ref="userBiz" scope="prototype" /> 19 20 <!-- 事务管理器 --> 21 <bean id="txManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory" /> 22 23 <!-- 事务增强 --> 24 <tx:advice id="txAdvice" transaction-manager="txManager"> 25 <tx:attributes> 26 <tx:method name="add*" propagation="REQUIRED" /> 27 <tx:method name="del*" propagation="REQUIRED" /> 28 <tx:method name="update*" propagation="REQUIRED" /> 29 <tx:method name="*" read-only="true" /> 30 </tx:attributes> 31 </tx:advice> 32 33 <!-- 事务切入点 --> 34 <aop:config> 35 <aop:pointcut id="bizPointcut" expression="execution(* biz.impl.*.*(..))" /> 36 <aop:advisor advice-ref="txAdvice" pointcut-ref="bizPointcut" /> 37 </aop:config> 38 </beans>
示例下载:SSH简单Demo.zip