ssh框架整合模板

Spring2.5+Hibernate3.3+Struts1.3整合开发


struts-config.xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
	<form-beans>
	<form-bean name="employeeForm" type="com.cz.web.forms.EmployeeForm" />
	</form-beans>
	<action-mappings>
	<action path="/login" parameter="flag" name="employeeForm">
	<forward name="ok" path="/WEB-INF/MainFrame.jsp"/>
	<forward name="err" path="/WEB-INF/login.jsp"/>	
	</action>
	<!-- 配置employeeaction -->
	<action path="/employee" name="employeeForm" parameter="flag">
	<forward name="goAddEmpUi" path="/WEB-INF/addEmpUi.jsp" />
	<forward name="goListEmp" path="/WEB-INF/listEmp.jsp"/>
	<forward name="goUpdEmpUi" path="/WEB-INF/updEmpUi.jsp"/>
	</action>
	</action-mappings>
	
	<!-- 配置全局跳转 -->
	<global-forwards>
	<forward name="opererr" path="/WEB-INF/err.jsp" />
	<forward name="operok" path="/WEB-INF/ok.jsp" />
	</global-forwards>
	
	<!-- 配置代理请求处理 DelegatingRequestProcessor ,它的用户是 -->
	<controller>
 	<set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor"/>
	</controller> 
	
</struts-config>
 

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">
<!--配置struts-->
<servlet>
	<servlet-name>struts</servlet-name>
	<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
	<init-param>
		<param-name>config</param-name>
		<param-value>/WEB-INF/struts-config.xml</param-value>
	</init-param>
	<load-on-startup>0</load-on-startup>
</servlet>
  <servlet>
    <description>This is the description of my J2EE component</description>
    <display-name>This is the display name of my J2EE component</display-name>
    <servlet-name>MyFilter</servlet-name>
    <servlet-class>com.cz.web.filter.MyFilter</servlet-class>
  </servlet>

<servlet-mapping>
	<servlet-name>struts</servlet-name>
	<url-pattern>*.do</url-pattern>
</servlet-mapping>
  <servlet-mapping>
    <servlet-name>MyFilter</servlet-name>
    <url-pattern>/MyFilter</url-pattern>
  </servlet-mapping>

<!-- 指定spring的配置文件,默认从web根目录寻找配置文件,我们可以通过spring提供的classpath:前缀指定从类路径下寻找 -->
<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- 对Spring容器进行实例化 -->
<listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- 配置自己写的过滤器 -->
<!--  
<filter>
<filter-name>MyFilter</filter-name>
<filter-class>com.cz.web.filter.MyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>MyFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>-->

<!-- 使用 spring框架自己提供的过滤器解决乱码 -->
<filter>
	<filter-name>encoding</filter-name>
	<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
	<init-param>
		<param-name>encoding</param-name>
		<param-value>UTF-8</param-value>
	</init-param>
</filter>
<filter-mapping>
	<filter-name>encoding</filter-name>
	<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 配置opensessioninview解决懒加载,本质一个过滤器. -->
<filter>
        <filter-name>OpenSessionInViewFilter</filter-name>
        <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
        <filter-name>OpenSessionInViewFilter</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:context="http://www.springframework.org/schema/context"
		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/context 

http://www.springframework.org/schema/context/spring-context-2.5.xsd
				http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-

tx-2.5.xsd">
<!-- 启用注解扫描 -->
<context:annotation-config/>
<!-- 配置和一个testService对象 -->
<bean id="testServcie" class="com.cz.test.TestServcie">
<property name="name" value="test"/>
</bean>

<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
	    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
	    <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl"/>
	    <property name="username" value="scott"/>
	    <property name="password" value="tiger"/>
	     <!-- 连接池启动时的初始值 -->
		<property name="initialSize" value="30"/>
	 	<!-- 连接池的最大值 -->
	 	<property name="maxActive" value="500"/> 
 		<!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 

-->
		<property name="maxIdle" value="2"/>
		<!--  最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->
		<property name="minIdle" value="1"/>
</bean>
<!-- 配置会话工厂() -->
<bean id="sessionFactory"  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
     <!-- 设置数据源 -->
     <property name="dataSource" ref="dataSource"/>
     <!-- 接管了hibernate对象映射文件 -->
     <property name="mappingResources">
	    <list>
	      <value>com/cz/domain/Employee.hbm.xml</value>
	      <value>com/cz/domain/Department.hbm.xml</value>
	    </list>
     </property>
     <property name="hibernateProperties">
	    <value>
	        	hibernate.dialect=org.hibernate.dialect.OracleDialect
	        	hibernate.hbm2ddl.auto=update
				hibernate.show_sql=true
				hibernate.cache.use_second_level_cache=true
        	    hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
        	    hibernate.generate_statistics=true	      
	 </value>
    </property>
</bean>

<!-- 配置EmployeeService对象 -->
<!--  
<bean id="employeeService" class="com.cz.service.imp.EmployeeService">
	<property name="sessionFactory" ref="sessionFactory" />
</bean>-->
<!-- 配置EmployeeService对象通过注解的方式来注入属性值,这是一个知识点 -->
<bean id="employeeService" class="com.cz.service.imp.EmployeeService"/>
<bean id="departmentService" class="com.cz.service.imp.DepartmentService">
	<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!-- 配置action -->
<bean name="/login" scope="prototype" class="com.cz.web.action.LoginAction"/>
<bean name="/employee" scope="prototype" class="com.cz.web.action.EmployeeAction">
<property name="departmentService" ref="departmentService"/>
<property name="employeeService" ref="employeeService"/>
</bean>

<!-- 配置事务管理器,统一管理sessionFactory的事务 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  	<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 启用事务注解 -->
<tx:annotation-driven transaction-manager="txManager"/>

</beans>

你可能感兴趣的:(SSH整合)