您的位置:首页 > 编程语言 > Java开发

三大框架(ssh)整合之配置文件

2016-12-19 18:20 381 查看
一.web配置文件web.xml

<!-- 解决session延迟加载 -->

    <filter>

        <filter-name>openSessionInView</filter-name>

        <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>

    </filter>

    <filter-mapping>

        <filter-name>openSessionInView</filter-name>

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

    </filter-mapping>

    <!-- 加载spring配置文件 -->

    <context-param>

        <param-name>contextConfigLocation&l
4000
t;/param-name>

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

    </context-param>

    <!--上下文加载监听器 -->

    <listener>

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

    </listener>

    <!--struts核心过滤器 -->

    <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>

        <dispatcher>REQUEST</dispatcher>

        <dispatcher>FORWARD</dispatcher>

    </filter-mapping>  


二.Struts2的配置文件struts.xml

<struts>

    <constant name="struts.devMode" value="true" />

    <constant name="struts.objectFactory" value="spring" />

   <!--配置国际化的消息提示--!>

    <constant name="struts.custom.i18n.resources" value="login-message" />

    <package name="defaultPackage" extends="struts-default">

<!--拦截器的配置(如果有需要)--!>
        <interceptors>

            <interceptor name="loginIntercepter"

                class="com.wuhan.bos.web.filter.LoginFilterInterceptor">

                <param name="excludeMethods">login</param>

            </interceptor>

            <interceptor-stack name="myStack">

                <interceptor-ref name="loginIntercepter"></interceptor-ref>

                <interceptor-ref name="defaultStack"></interceptor-ref>

            </interceptor-stack>

        </interceptors>

        <default-interceptor-ref name="myStack"></default-interceptor-ref>

<!--全局视图的配置(如果有需要)--!>
        <global-results>

            <result name="login">/login.jsp</result>

            <result name="unauthorizedUrl">/unauthorized.jsp</result>

        </global-results>

    <!--异常结果视图(如果有需要)--!>

        <global-exception-mappings>

            <exception-mapping result="unauthorizedUrl"

                exception="org.apache.shiro.authz.UnauthorizedException"></exception-mapping>

        </global-exception-mappings>

    </package>

</struts>  


三.Spring的配置文件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" xmlns:tool="http://www.springframework.org/schema/tool"

    xmlns:context="http://www.springframework.org/schema/context"

    xsi:schemaLocation="

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

        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd

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

        http://www.springframework.org/schema/tool/spring-tool-3.2.xsd

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

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

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

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

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

        http://www.springframework.org/schema/context/spring-context.xsd

        ">

    <!-- 开启spring注解开发 -->

    <context:component-scan base-package="com.wuhan.bos" />

    <!-- 加载jdbc配置文件 -->

    <context:property-placeholder location="classpath:jdbc.properties" />

    <!-- 开启事务注解 -->

    <tx:annotation-driven transaction-manager="txManager" />

    <bean id="txManager"

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

        <property name="sessionFactory" ref="sessionFactory" />

    </bean>

    <!--工厂bean (已经整合了hibernate)-->

    <bean id="sessionFactory"

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

        <property name="dataSource" ref="dataSource" />

        <property name="hibernateProperties">

            <props>

                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>

                <prop key="hibernate.show_sql">true</prop>

                <prop key="hibernate.format_sql">false</prop>

            </props>

        </property>

        <!--配置hibernate映射 -->

        <property name="mappingDirectoryLocations">

            <list>

                <value>classpath:com/wuhan/bos/domain</value>

            </list>

        </property>

    </bean>

    <!-- c3p0数据源 dataSource -->

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">

        <property name="driverClass" value="${driverClass}"></property>

        <property name="jdbcUrl" value="${jdbcUrl}"></property>

        <property name="user" value="${user}"></property>

        <property name="password" value="${password}"></property>

    </bean>

    <!-- 远程调用服务 -->

    <bean id="customerService"

        class="org.springframework.remoting.caucho.HessianProxyFactoryBean">

        <property name="serviceInterface" value="cn.itcast.crm.service.CustomerService" />

        <property name="serviceUrl" value="http://localhost:8080/crm/remoting/customer"></property>

    </bean>

</beans>


四.hibernate的配置文件(已经整合到了Spring的配置文件中了,也可单独配置hibernate-cfg.xml文件,然后配置到sessionFactory中)

    
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息