标签:ppi .com ring ica cti 持久层 use 监听 web
一:配置文件整合SSH
1.创建Hibernate实体类的映射文件,一般在resource下建文件夹下放置
<?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">
<!--创建映射文件-->
<hibernate-mapping>
<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>
</hibernate-mapping>
2.Struts.xml文件的配置
<?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方法配置-->
<struts>
<constant name="struts.devMode" value="true"/>
<!--允许动态方法调用-->
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<package name="my" extends="struts-default">
<action name="user" class="userAction">//在Spring文件中创建的bean
<result>/list.jsp</result>
</action>
</package>
</struts>
3.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--数据源-->
<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>
<!--创建session工厂-->
<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>
<!--定义事物管理器(声明事物)-->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!--持久层-->
<bean id="userDao" class="cn.yunhe.dao.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!--业务层-->
<bean id="userBiz" class="cn.yunhe.biz.UserBizImpl">
<property name="userDao" ref="userDao"/>
</bean>
<!--控制层-->
<bean id="userAction" class="cn.yunhe.controller.UserController">
<property name="userBiz" ref="userBiz"/>
</bean>
</beans>
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的过滤器-->
<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的监听器,在系统启动的时候创建spring容器-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
5.Spring+Struts+Hibernate配置文件整合
标签:ppi .com ring ica cti 持久层 use 监听 web
原文地址:http://www.cnblogs.com/lxiaoyang/p/7214426.html