本文转载自:
http://www.blogjava.net/gcw633/archive/2010/04/19/318731.html
1.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的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext-*.xml</param-value>
</context-param>
<!-- hibernate过滤器 -->
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<!-- struts2过滤器 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 编码过滤器 -->
<filter>
<filter-name>encodingFilter</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>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
2.hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools.-->
<hibernate-configuration>
<session-factory>
<property name="connection.username">sa</property>
<property name="connection.url">jdbc:sqlserver://localhost:1433;databaseName=demo</property>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="myeclipse.connection.profile">s2shcon2</property>
<property name="connection.password">sa</property>
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">true</property>
<mapping resource="com/test/entity/Users.hbm.xml" />
</session-factory>
</hibernate-configuration></beans>
3.applicationContext-*.xml
(1)applicationContext-common.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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- 配置SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 配置事务管理 -->
<bean id="transactionBase"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
lazy-init="true" abstract="true">
<!-- 配置事务管理器 -->
<property name="transactionManager" ref="transactionManager" />
<!-- 配置事务属性 -->
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
(2)applicationContext-bean.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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- 将sessionFactory注入到数据访问层dao中 -->
<!-- 用户管理 -->
<bean id="userDao" parent="transactionBase" >
<property name="target">
<bean class="com.test.dao.impl.UserDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
</property>
</bean>
</beans>
(3)applicationContext-service.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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- 将数据访问层中的dao注入到逻辑层中的service中 -->
<bean id="userBiz" class="com.test.biz.impl.UserBizImpl">
<property name="userDao" ref="userDao"></property>
</bean>
</beans>
(4)applicationContext-actions.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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- 将逻辑层中的service注入到action中 -->
<bean id="loginAction" class="com.test.actions.LoginAction" scope="prototype">
<property name="userBiz" ref="userBiz"></property>
</bean>
</beans>
(5)struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="struts2" extends="struts-default" namespace="/">
<action name="login" class="loginAction">
<result name="success">/index.jsp</result>
<result name="input">/login.jsp</result>
<result name="error">/login.jsp</result>
</action>
</package>
</struts>
分享到:
相关推荐
s2sh整合步骤及配置文件配置s2sh整合步骤及配置文件配置s2sh整合步骤及配置文件配置s2sh整合步骤及配置文件配置
为刚入门的学习人员提供些整合的思路
S2SH整合后的相关完整配置文件,beans.xml,struts.xml,log4j.properties以及web.xml
struts,hibernate,spring框架包整合与相关配置文件的配置
Struts2.0.14+Spring2.5+Hibernate3.2+Oracle10g+Tomcat6.0开发环境配置,有步骤图示 +web.xml+applicationContext.xml文件配置 还算齐全。。。
s2sh整合,s2sh,langsin,浪曦oa工作流源码。上传有限。里面没带jar文件 配置完整.
struts2 spring hibernate的完整整合,包括的 配置文件和注解的不同方式
继《使用Annotation并对DAO层封装具有分页功能的S2SH整合实例》系列后
应上面配置文件篇,这次发布的是用注解写的。
strruts2.1、Spring3.0、Hibernate3.3整合与S2SH的XML文件拆分.docx
S2SH整合后,applicationContext-hibernate.xml中可以配置不同的数据库,写在txt文件中
整合了struts2.1.8,spring2.5,hibernate3在项目中所必须的基本包,包括配置文件
适合初学者学习配置文件的配置,有助于养成分层的观念!
自己整合了一个可以运行的完整的S2SH框架(struts-2.3.16.1/hibernate-3.6.10/spring-framework-3.2.9),包含了所有的配置文件和所有必需的jar包。以后备用。。。
此时如果使用基于Annotation的SSH框架很容易转移到Struts+EJB+Spring的项目中,而且使用Annotation,很容易实现0配置,像在这个实例中就一个配置,这样避免了配置文件多而不知所措的情况。 开发步骤 2 环境的集成 2 ...
一个空的S2SH整合后的项目,留着自己用,主要是jar包和配置文件,基于基本的配置文件方式搭建
刚学习struts2,写了一个s2sh整合的例子供大家分享,没什么难的,就是配置文件的格式太难找了.
对于刚进入职场的朋友适合的一款整合,本人亲自搭建,jar包和配置文件都在里面,划分了dao永久层,service逻辑层,controller控制层,下载直接导入,然后修改部分配置文件就可以使用,亲测有效。如果导入错误太多,...
虽然后台逻辑并不复杂,但已经包含了架构基于s2sh技术型系统的全部基础部分:如分页,缓存,文件上传,连接池等。很适合学习使用,希望对初学JavaEE WEB开的人有所帮助。 这个资源在去年发布了第一版,已经有很多...
下载解压后,把jar包直接放入lib下即可。基本上开发中需要的jar包都有。 只要你S2SH配置文件没问题,运行起来绝对没问题。