配置S2SH步骤

1.    创建一个空的Web Project

2.导入strtus2.3的jar包

commons-fileupload-1.2.2.jar

commons-io-2.0.1.jar

commons-lang-2.5.jar

freemarker-2.3.18.jar

ognl-3.0.4.jar

struts2-core-2.3.1.2.jar

xwork-core-2.3.1.2.jar

2.    在src下创建struts.xml

<?xml version="1.0"encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC

    "-//Apache Software Foundation//DTD StrutsConfiguration 2.0//EN"

   "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

</struts>

3.    在web.xml配置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>

4.    导入Hibernate3.6的jar包

antlr-2.7.6.jar

c3p0-0.9.1.jar

cglib-2.2.jar

commons-collections-3.1.jar

dom4j-1.6.1.jar

hibernate3.jar

hibernate-jpa-2.0-api-1.0.1.Final.jar

javassist-3.12.0.GA.jar

jta-1.1.jar

slf4j-api-1.6.1.jar

struts2-spring-plugin-2.3.1.2.jar

5.    在src下创建hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>

<!DOCTYPE hibernate-configuration PUBLIC

        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"

      "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory> 

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>

        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>

        <property name="hibernate.connection.username">root</property>

        <property name="hibernate.connection.password">root</property>

        <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>

        <property name="show_sql">true</property>

        <property name="hbm2ddl.auto">update</property>

        <mapping resource="com/test/model/User.hbm.xml"/>

   </session-factory>

</hibernate-configuration>

6.    导入Spring3.1的jar包及其需要的包

aopalliance.jar

aspectjweaver.jar

commons-logging-1.1.1.jar

log4j-1.2.16.jar

org.springframework.aop-3.1.0.RELEASE.jar

org.springframework.asm-3.1.0.RELEASE.jar

org.springframework.aspects-3.1.0.RELEASE.jar

org.springframework.beans-3.1.0.RELEASE.jar

org.springframework.context-3.1.0.RELEASE.jar

org.springframework.core-3.1.0.RELEASE.jar

org.springframework.expression-3.1.0.RELEASE.jar

org.springframework.jdbc-3.1.0.RELEASE.jar

org.springframework.orm-3.1.0.RELEASE.jar

org.springframework.transaction-3.1.0.RELEASE.jar

org.springframework.web-3.1.0.RELEASE.jar

7.    在src下创建applicationContext-common.xml文件

该文件完成sessionFactory、事务的配置

<?xml version="1.0"encoding="UTF-8"?>

<beansxmlns="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-3.0.xsd

      http://www.springframework.org/schema/tx

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

      http://www.springframework.org/schema/aop

      http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

      <!--配置sessionFactory -->

      <beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

                    <propertyname="configLocation">

                                  <value>classpath:hibernate.cfg.xml</value>

                    </property>             

      </bean>

      <!--配置事务管理器 -->

      <beanid="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">

                    <propertyname="sessionFactory">

                                  <refbean="sessionFactory"/>

                    </property>             

      </bean>

      <!--配置事务的传播特性 -->

      <tx:adviceid="txAdvice" transaction-manager="transactionManager">

                    <tx:attributes>

                                  <tx:methodname="add*" propagation="REQUIRED"/>

                                  <tx:methodname="del*" propagation="REQUIRED"/>

                                  <tx:methodname="update*" propagation="REQUIRED"/>

                                  <tx:methodname="*" read-only="true"/>

                    </tx:attributes>

      </tx:advice>

      <!--那些类的哪些方法参与事务 -->

      <aop:config>

                    <aop:pointcutid="allManagerMethod" expression="execution(*com.test.service.*.*(..))"/>

                    <aop:advisorpointcut-ref="allManagerMethod" advice-ref="txAdvice"/>

      </aop:config>

</beans>

8.    在web.xml配置spring

Spring的配置要放在Struts的filter前面

<context-param>

                            <param-name>contextConfigLocation</param-name>

                            <param-value>classpath*:applicationContext-*.xml</param-value>

              </context-param>

              <listener>

                            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

              </listener>

              <filter>

                            <filter-name>Springcharacter encoding filter</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>Springcharacter encoding filter</filter-name>

                            <url-pattern>/*</url-pattern>

              </filter-mapping>

              <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>/*</url-pattern>

              </filter-mapping>

最终包层次:

要想查看例子,请到http://download.csdn.net/detail/simplestar_ht/4273187下载

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值