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

一.web配置文件web.xml
   
   
  1. <!-- 解决session延迟加载 -->
  2.     <filter>
  3.         <filter-name>openSessionInView</filter-name>
  4.         <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
  5.     </filter>
  6.     <filter-mapping>
  7.         <filter-name>openSessionInView</filter-name>
  8.         <url-pattern>/*</url-pattern>
  9.     </filter-mapping>
  10.     <!-- 加载spring配置文件 -->
  11.     <context-param>
  12.         <param-name>contextConfigLocation</param-name>
  13.         <param-value>classpath:applicationContext.xml</param-value>
  14.     </context-param>
  15.     <!--上下文加载监听器 -->
  16.     <listener>
  17.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  18.     </listener>
  19.     <!--struts核心过滤器 -->
  20.     <filter>
  21.         <filter-name>struts2</filter-name>
  22.         <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  23.     </filter>
  24.     <filter-mapping>
  25.         <filter-name>struts2</filter-name>
  26.         <url-pattern>/*</url-pattern>
  27.         <dispatcher>REQUEST</dispatcher>
  28.         <dispatcher>FORWARD</dispatcher>
  29.     </filter-mapping>  
二.Struts2的配置文件struts.xml
   
   
  1. <struts>
  2.     <constant name="struts.devMode" value="true" />
  3.     <constant name="struts.objectFactory" value="spring" />
  4.    <!--配置国际化的消息提示--!>
  5.     <constant name="struts.custom.i18n.resources" value="login-message" />
  6.     <package name="defaultPackage" extends="struts-default">
  7. <!--拦截器的配置(如果有需要)--!>
  8.         <interceptors>
  9.             <interceptor name="loginIntercepter"
  10.                 class="com.wuhan.bos.web.filter.LoginFilterInterceptor">
  11.                 <param name="excludeMethods">login</param>
  12.             </interceptor>
  13.             <interceptor-stack name="myStack">
  14.                 <interceptor-ref name="loginIntercepter"></interceptor-ref>
  15.                 <interceptor-ref name="defaultStack"></interceptor-ref>
  16.             </interceptor-stack>
  17.         </interceptors>
  18.         <default-interceptor-ref name="myStack"></default-interceptor-ref>
  19. <!--全局视图的配置(如果有需要)--!>
  20.         <global-results>
  21.             <result name="login">/login.jsp</result>
  22.             <result name="unauthorizedUrl">/unauthorized.jsp</result>
  23.         </global-results>
  24.    <!--异常结果视图(如果有需要)--!>
  25.         <global-exception-mappings>
  26.             <exception-mapping result="unauthorizedUrl"
  27.                 exception="org.apache.shiro.authz.UnauthorizedException"></exception-mapping>
  28.         </global-exception-mappings>
  29.     </package>
  30. </struts>  
三.Spring的配置文件applicationContext.xml
    
    
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
  4.     xmlns:tx="http://www.springframework.org/schema/tx" xmlns:tool="http://www.springframework.org/schema/tool"
  5.     xmlns:context="http://www.springframework.org/schema/context"
  6.     xsi:schemaLocation="
  7.         http://www.springframework.org/schema/beans 
  8.         http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  9.         http://www.springframework.org/schema/tool 
  10.         http://www.springframework.org/schema/tool/spring-tool-3.2.xsd
  11.         http://www.springframework.org/schema/tx 
  12.         http://www.springframework.org/schema/tx/spring-tx.xsd
  13.         http://www.springframework.org/schema/aop
  14.         http://www.springframework.org/schema/aop/spring-aop.xsd
  15.         http://www.springframework.org/schema/context 
  16.         http://www.springframework.org/schema/context/spring-context.xsd
  17.         ">
  18.     <!-- 开启spring注解开发 -->
  19.     <context:component-scan base-package="com.wuhan.bos" />
  20.     <!-- 加载jdbc配置文件 -->
  21.     <context:property-placeholder location="classpath:jdbc.properties" />
  22.     <!-- 开启事务注解 -->
  23.     <tx:annotation-driven transaction-manager="txManager" />
  24.     <bean id="txManager"
  25.         class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  26.         <property name="sessionFactory" ref="sessionFactory" />
  27.     </bean>
  28.     <!--工厂bean (已经整合了hibernate)-->
  29.     <bean id="sessionFactory"
  30.         class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  31.         <property name="dataSource" ref="dataSource" />
  32.         <property name="hibernateProperties">
  33.             <props>
  34.                 <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
  35.                 <prop key="hibernate.show_sql">true</prop>
  36.                 <prop key="hibernate.format_sql">false</prop>
  37.             </props>
  38.         </property>
  39.         <!--配置hibernate映射 -->
  40.         <property name="mappingDirectoryLocations">
  41.             <list>
  42.                 <value>classpath:com/wuhan/bos/domain</value>
  43.             </list>
  44.         </property>
  45.     </bean>
  46.     <!-- c3p0数据源 dataSource -->
  47.     <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  48.         <property name="driverClass" value="${driverClass}"></property>
  49.         <property name="jdbcUrl" value="${jdbcUrl}"></property>
  50.         <property name="user" value="${user}"></property>
  51.         <property name="password" value="${password}"></property>
  52.     </bean>
  53.     <!-- 远程调用服务 -->
  54.     <bean id="customerService"
  55.         class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
  56.         <property name="serviceInterface" value="cn.itcast.crm.service.CustomerService" />
  57.         <property name="serviceUrl" value="http://localhost:8080/crm/remoting/customer"></property>
  58.     </bean>
  59. </beans>
四.hibernate的配置文件(已经整合到了Spring的配置文件中了,也可单独配置hibernate-cfg.xml文件,然后配置到sessionFactory中)
    





  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hspringh

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值