One: Configuration file consolidation ssh
1. Create a mapping file for Hibernate entity classes, typically placed under the resource folder
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE hibernate-mapping Public
"-//hibernate/hibernate Mapping DTD 3.0//en"
"Http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<!--Create a mapping file--
<class name= "Cn.yunhe.model.User" table= "User" >
<id name= "id" column= "id" type= "Java.lang.Integer" >
<generator class= "native"/>
</id>
<property name= "name" type= "java.lang.String"/>
<property name= "pwd" type= "java.lang.String"/>
<property name= "Age" type= "Java.lang.Integer"/>
</class>
Configuration of the 2.struts.xml file
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE Struts Public
"-//apache software foundation//dtd Struts Configuration 2.3//en"
"Http://struts.apache.org/dtds/struts-2.3.dtd" >
<!--struts Method configuration-
<struts>
<constant name= "Struts.devmode" value= "true"/>
<!--allow dynamic method calls--
<constant name= "Struts.enable.DynamicMethodInvocation" value= "true"/>
<package name= "My" extends= "Struts-default" >
<action name= "user" class= "useraction" >//the bean created in the spring file
<result>/list.jsp</result>
</action>
</package>
</struts>
Configuration of 3.Spring files
<?xml version= "1.0" encoding= "UTF-8"?>
<beans xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans.xsd ">
<!--data Source-
<bean id= "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" >
<property name= "Driverclass" value= "Com.mysql.jdbc.Driver"/>
<property name= "Jdbcurl" value= "Jdbc:mysql://localhost:3306/test"/>
<property name= "User" value= "root"/>
<property name= "Password" value= "076634"/>
</bean>
<!--Create Session factory--
<bean id= "Sessionfactory" class= "Org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
<property name= "DataSource" ref= "DataSource"/>
<property name= "Mappingresources" >
<list>
<value>hbm/User.hbm.xml</value>
</list>
</property>
</bean>
<!--define things manager (declare things)--
<bean id= "TransactionManager" class= "Org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name= "Sessionfactory" ref= "Sessionfactory"/>
</bean>
<!--durable layers--
<bean id= "Userdao" class= "Cn.yunhe.dao.UserDaoImpl" >
<property name= "Sessionfactory" ref= "Sessionfactory"/>
</bean>
<!--business Layer--
<bean id= "userbiz" class= "Cn.yunhe.biz.UserBizImpl" >
<property name= "Userdao" ref= "Userdao"/>
</bean>
<!--control Layer--
<bean id= "useraction" class= "Cn.yunhe.controller.UserController" >
<property name= "userbiz" ref= "userbiz"/>
</bean>
</beans>
Configuration of the 4.web.xml
<web-app>
<display-name>archetype Created Web application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param>
<!--struts Filters--
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--spring Listener to create a spring container when the system is started--
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
5.spring+struts+hibernate Configuration file Consolidation