SSH2配置单详解(Struts2 Hibernate3 Spring)

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配置文件位置,可以定义多个文件,也可以使用通配符 -->

    <context-param>

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

       <param-value>

           /WEB-INF/classes/applicationContext*.xml

       </param-value>

    </context-param>

 

    <!-- 配置Spring过滤器 -->

    <!-- 作用:启动web应用,就加载Spring,让Spring管理Bean -->

    <listener>

       <listener-class>

           org.springframework.web.context.ContextLoaderListener

       </listener-class>

    </listener>

 

    <!-- 解决hibernate延迟加载出现的问题,要放在Struts2过滤器之前 -->

    <!-- 作用:Spring管理hibernateSession,在事务管理的类执行完后,不立刻关闭Session

        而将Session保存在一个线程变量中,在线程退出前关闭Session;这样在整个request过程中

        始终使用一个session,也就可以在request的任何时期lazy loading数据。

        主要是为了实现hibernate的延迟加载功能 -->

    <filter>

       <filter-name>lazyLoadingFilter</filter-name>

       <filter-class>

           org.springframework.orm.hibernate3.support.OpenSessionInViewFilter

       </filter-class>

       <!-- singleSession默认设置为true,如何为false就等于没有设置OpenSessionInView -->

       <init-param>

           <param-name>singleSession</param-name>

           <param-value>true</param-value>

       </init-param>

    </filter>

 

    <!-- Struts2过滤器 -->

    <filter>

       <filter-name>struts2</filter-name>

       <filter-class>

           org.apache.struts2.dispatcher.FilterDispatcher

       </filter-class>

    </filter>

 

    <!-- 解决hibernate延迟加载出现的问题,仍需要放在Struts2过滤器的filter-mapping之前 -->

    <filter-mapping>

       <filter-name>lazyLoadingFilter</filter-name>

       <url-pattern>*.action</url-pattern>

    </filter-mapping>

    <!-- Struts2过滤器的filter-mapping -->

    <filter-mapping>

       <filter-name>struts2</filter-name>

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

    </filter-mapping>

 

    <welcome-file-list>

       <welcome-file>index.jsp</welcome-file>

    </welcome-file-list>

</web-app>


applicationContext.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.0.xsd

           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd

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

    default-autowire="byName" default-lazy-init="true">

 

    <bean id="dataSource"

       class="org.apache.commons.dbcp.BasicDataSource">

       <property name="driverClassName">

           <value>oracle.jdbc.driver.OracleDriver</value>

       </property>

       <property name="url">

           <value>jdbc:oracle:thin:@192.168.2.168:1521:orcl</value>

       </property>

       <property name="username">

           <value>huahua</value>

       </property>

       <property name="password">

           <value>111111</value>

       </property>

    </bean>

 

    <bean id="sessionFactory"

       class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

       <property name="dataSource">

           <ref bean="dataSource" />

       </property>

       <property name="hibernateProperties">

           <props>

              <prop key="hibernate.dialect">

                  org.hibernate.dialect.Oracle9Dialect

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值