S2SH整合-Struts2.14+spirng3.0+hibernate3.2

首先加入Struts2.14的JAR包,
S2SH整合-Struts2.14+spirng3.0+hibernate3.2
再是HibernateJAR包
S2SH整合-Struts2.14+spirng3.0+hibernate3.2
然后再是SpringJAR包
S2SH整合-Struts2.14+spirng3.0+hibernate3.2
,由于是用idea开发,有些其他要用的的包没有自动增加,所也也要加进来,具体是
commons-dbcp.jar
commons-pool.jar
servlet-api.jar
ojdbc14.jar
包就这么多了。现在是配置文件:
web.xml
<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/application*.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!--这个openSessionInViewFitler要配在struts的Filter前面,否则会报,no session错 -->
    <filter>
        <filter-name>openSessionInViewFitler</filter-name>
        <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    </filter>
     <filter-mapping>
         <filter-name>openSessionInViewFitler</filter-name>
         <url-pattern>/*</url-pattern>
     </filter-mapping>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

再是struts.xml
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <!-- 与SPRING集成,类由SPRING生成 -->
    <constant name="struts.objectFactory" value="spring" />
    <!-- 开发模式,这样可以打印出更详细的错误信息 -->
    <constant name="struts.devMode" value="true" />
    <!-- 设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 -->
    <constant name="struts.serve.static.browserCache" value="false" />
    <!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开 -->
    <constant name="struts.configuration.xml.reload" value="true" />
    <!-- 编码格式-->
    <constant name="struts.custom.i18n.resources" value="utf-8" />
    <package name="ssh2" extends="struts-default" namespace="/">
        <action name="login" class="loginAction">
            <result name="success">/jsp/welcome.jsp</result>
            <result name="error">/jsp/error.jsp</result>
        </action>
        <!--这里的class是spring中的bean id -->
        <action name="myAction" class="myAction">
            <result name="success">/jsp/listAction.jsp</result>
            <result name="error">/jsp/error.jsp</result>
        </action>
    </package>
</struts>

application.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: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-2.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="url" value="jdbc:oracle:thin:test/[email protected]:1521:testdb"></property>
        <property name="username" value="test"></property>
        <property name="password" value="123456"></property>
        <property name="driverClassName" value="oracle.jdbc.OracleDriver"></property>
    </bean>    

    <bean id="sessionFactory"
          class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
          destroy-method="destroy">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.OracleDialect
                </prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
        <property name="mappingResources">
            <list>
                <value>com/ssh/bean/User.hbm.xml</value>
                 <value>com/ssh/bean/Action.hbm.xml</value>
            </list>
        </property>
    </bean>

    <!--<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> -->
        <!--hibernate 注解类
        <property name="configurationClass">
            <value>org.hibernate.cfg.AnnotationConfiguration</value>
        </property>     -->
        <!--hibernate 配置文件
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
    </bean>
                -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>

     <tx:advice id="smAdvice" transaction-manager="transactionManager">
         <tx:attributes>
             <tx:method name="save*" propagation="REQUIRED" />
             <tx:method name="del*" propagation="REQUIRED" />
             <tx:method name="update*" propagation="REQUIRED" />
             <tx:method name="login*" propagation="REQUIRED" />
         </tx:attributes>
     </tx:advice>
    <aop:config>
        <aop:pointcut id="smMethod" expression="execution(* com.ssh.service.impl.*.*(..))" />
        <aop:advisor advice-ref="smAdvice" pointcut-ref="smMethod"/>
    </aop:config>

    <bean id="loginAction" class="com.ssh.action.LoginAction" scope="prototype">
        <property name="userService" ref="UserService"/>
    </bean>
    <bean id="myAction" class="com.ssh.action.MyAction">
        <property name="actionService" ref="ActionService"/>
    </bean>
</beans>

这样子应该就可以运行起来了

你可能感兴趣的:(spring,Hibernate,jsp,xml,struts)