欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

S2SH 配置文件

程序员文章站 2022-03-04 17:52:48
...

struts.xml源码:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!-- struts2委托spring管理 -->
<constant name="struts.objectFactory" value="spring"/>
<!-- /crm/emp/add.action -->
<package name="crm_employee" extends="struts-default" namespace="/emp">
<action name="add" class="addBean" method="add">
<result>add.action</result>
<result>/emp/add_suc.jsp</result>
</action>
<action name="list" class="listBean" method="list">
<result>/emp/list.jsp</result>
</action>
<action name="delete" class="deleteBean" method="delete">
<result>delete.action</result>
<result>/emp/delete_suc.jsp</result>
</action>
<action name="update" class="updateBean" method="update">
<result>update.action</result>
<result>/emp/edit_suc.jsp</result>
</action>
<action name="edit" class="editBean" method="edit">
<result>/emp/edit.jsp</result>
</action>
<!-- Add actions here -->
</package>
</struts>

web.xml源码:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- 配置spring的监听器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
<!-- 开启监听 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- 配置OpenSessionInViewFilter,必须在struts2监听之前 -->
<filter>
<filter-name>lazyLoadingFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<!-- 设置监听加载上下文 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>lazyLoadingFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

applicationContext.xml源码:

<?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.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<!-- 配置Hibernate支持 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/tables">
</property>
<property name="username" value="root"></property>
<property name="password" value="hicc"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/sy/crm/model/Employee.hbm.xml</value>
</list>
</property>
</bean>
<bean id="employeeDao"
class="com.sy.crm.dao.hibernate.EmployeeDaoHibernate">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="employeeManager"
class="com.sy.crm.service.impl.EmployeeManagerImpl">
<property name="employeeDao">
<ref bean="employeeDao" />
</property>
</bean>

<bean id="addBean" class="com.sy.crm.action.EmployeeAction" scope="prototype">
<property name="employeeManager">
<ref bean="employeeManager" />
</property>
</bean>
<bean id="listBean" class="com.sy.crm.action.EmployeeAction" scope="prototype">
<property name="employeeManager">
<ref bean="employeeManager" />
</property>
</bean>
<bean id="deleteBean" class="com.sy.crm.action.EmployeeAction" scope="prototype">
<property name="employeeManager">
<ref bean="employeeManager" />
</property>
</bean>
<bean id="updateBean" class="com.sy.crm.action.EmployeeAction" scope="prototype">
<property name="employeeManager">
<ref bean="employeeManager" />
</property>
</bean>
<bean id="editBean" class="com.sy.crm.action.EmployeeAction" scope="prototype">
<property name="employeeManager">
<ref bean="employeeManager" />
</property>
</bean>
<!-- 事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!-- 配置事务特性,配置add,delete,update开始的方法,事务传播特性为required -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 配置那些类的方法进行事务管理,当前com.sy.crm.service包中的子包,
类中所有方法需要,还需要参考tx:advice的设置 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(*
com.sy.crm.service.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
</aop:config>
</beans>

http://www.cnblogs.com/shiyangxt/archive/2008/09/27/1301092.html


相关标签: javaee