spring上下文在web.xml中的配置

http://blog.csdn.net/xwygn/article/details/8444098


[java]  view plain copy
  1. <!-- Spring配置文件开始  -->      
  2.   <context-param>  
  3.       <param-name>contextConfigLocation</param-name>  
  4.       <param-value>classpath*:com/avicit/resource/spring/spring-base.xml</param-value>  
  5.   </context-param>  
  6.   
  7.   
  8.   <listener>  
  9.       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  10.   </listener>  
  11.     
  12.   <!-- Spring配置文件结束 -->  

对于

[java]  view plain copy
  1. org.springframework.web.context.ContextLoaderListener  
可以参见

http://blog.csdn.net/seng3018/article/details/6758860 中的说明

一般spring上下文中xml默认叫applicationContext.xml

[java]  view plain copy
  1. <!-- 扫描注解Bean -->  
  2.     <context:component-scan base-package="com.avicit">  
  3.         <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>  
  4.     </context:component-scan>  
  5.   
  6.     <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  7.         <property name="locations">  
  8.             <list>  
  9.                 <value>classpath*:com/avicit/resource/jdbc/jdbc.properties</value>  
  10.                 <value>classpath*:com/avicit/resource/hibernate/hibernate.properties</value>  
  11.             </list>  
  12.         </property>  
  13.     </bean>  
  14.   
  15.    
  16.     <!-- 国际化的消息资源文件 -->  
  17.     <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">  
  18.         <property name="basenames">  
  19.             <list>  
  20.                 <!-- 在web环境中一定要定位到classpath 否则默认到当前web应用下找  -->  
  21.                 <value>classpath:com/avicit/resource/message/messages</value>  
  22.             </list>  
  23.         </property>  
  24.         <property name="defaultEncoding" value="UTF-8"/>  
  25.         <property name="cacheSeconds" value="60"/>  
  26.     </bean>  
  27.       
  28.     <import resource="classpath*:com/avicit/resource/spring/spring-dao.xml"/>  
[java]  view plain copy
  1. <import resource="classpath*:com/avicit/resource/spring/spring-dao.xml"/>  
这里导入了另一个配置文件,就是配置数据源的

[java]  view plain copy
  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:p="http://www.springframework.org/schema/p"  
  4.     xmlns:context="http://www.springframework.org/schema/context"  
  5.     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"  
  6.   
  7.   
  8.     xsi:schemaLocation="  
  9.         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
  10.         http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.0.xsd  
  11.         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  
  12.         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">  
  13.   
  14.   
  15.     <bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">  
  16.         <property name="alias" value="proxoolDataSource" />  
  17.         <property name="driver" value="${jdbc.driver}" />  
  18.         <property name="driverUrl" value="${jdbc.url}" />  
  19.         <property name="user" value="${jdbc.username}" />  
  20.         <property name="password" value="${jdbc.password}" />  
  21.         <property name="maximumConnectionCount" value="${jdbc.maximum.connection.count}" />  
  22.         <property name="minimumConnectionCount" value="${jdbc.minimum.connection.count}" />  
  23.         <property name="statistics" value="${jdbc.statistics}" />  
  24.         <property name="simultaneousBuildThrottle" value="${jdbc.simultaneous.build.throttle}" />  
  25.     </bean>  
  26.   
  27.   
  28.     <bean id="sessionFactory"  
  29.         class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">  
  30.         <property name="dataSource" ref="dataSource" />  
  31.         <property name="packagesToScan" value="com.avicit" />  
  32.         <property name="hibernateProperties">  
  33.             <props>  
  34.                 <prop key="hibernate.dialect">${hibernate.dialect}</prop>  
  35.                 <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>  
  36.                 <prop key="hibernate.format_sql">true</prop>  
  37.                 <prop key="hibernate.query.substitutions">${hibernate.query.substitutions}</prop>  
  38.                 <prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop>  
  39.                 <prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>  
  40.                 <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>  
  41.                 <prop key="hibernate.bytecode.use_reflection_optimizer">${hibernate.bytecode.use_reflection_optimizer}</prop>  
  42.   
  43.   
  44.                 <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>  
  45.                 <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>  
  46.                 <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>  
  47.                 <prop key="net.sf.ehcache.configurationResourceName">${net.sf.ehcache.configurationResourceName}</prop>  
  48.                 <prop key="hibernate.cache.use_structured_entries">${hibernate.cache.use_structured_entries}</prop>  
  49.             </props>  
  50.         </property>  
  51.     </bean>  
  52.   
  53.   
  54.     <bean id="lookupResolver"  
  55.         class="com.avicit.framework.support.matchrule.context.HibernateMatchRuleResolver">  
  56.         <property name="packagesToScan" value="com.avicit.fes.*" />  
  57.     </bean>  
  58.   
  59.   
  60.     <!-- 开启AOP监听 只对当前配置文件有效 -->  
  61.     <aop:aspectj-autoproxy expose-proxy="true" />  
  62.   
  63.   
  64.     <!-- 开启注解事务 只对当前配置文件有效 -->  
  65.     <tx:annotation-driven transaction-manager="txManager" />  
  66.   
  67.   
  68.     <bean id="txManager"  
  69.         class="org.springframework.orm.hibernate4.HibernateTransactionManager">  
  70.         <property name="sessionFactory" ref="sessionFactory" />  
  71.     </bean>  
  72.   
  73.   
  74.     <tx:advice id="txAdvice" transaction-manager="txManager">  
  75.         <tx:attributes>  
  76.             <tx:method name="save*" propagation="REQUIRED" />  
  77.             <tx:method name="add*" propagation="REQUIRED" />  
  78.             <tx:method name="create*" propagation="REQUIRED" />  
  79.             <tx:method name="insert*" propagation="REQUIRED" />  
  80.             <tx:method name="update*" propagation="REQUIRED" />  
  81.             <tx:method name="merge*" propagation="REQUIRED" />  
  82.             <tx:method name="del*" propagation="REQUIRED" />  
  83.             <tx:method name="remove*" propagation="REQUIRED" />  
  84.             <tx:method name="put*" propagation="REQUIRED" />  
  85.             <tx:method name="use*" propagation="REQUIRED" />  
  86.             <!--hibernate4必须配置为开启事务 否则 getCurrentSession()获取不到 -->  
  87.             <tx:method name="get*" propagation="REQUIRED" read-only="true" />  
  88.             <tx:method name="count*" propagation="REQUIRED" read-only="true" />  
  89.             <tx:method name="find*" propagation="REQUIRED" read-only="true" />  
  90.             <tx:method name="list*" propagation="REQUIRED" read-only="true" />  
  91.             <tx:method name="*" read-only="true" />  
  92.         </tx:attributes>  
  93.     </tx:advice>  
  94.     <aop:config expose-proxy="true">  
  95.         <!-- 只对业务逻辑层实施事务 -->  
  96.         <aop:pointcut id="txPointcut"  
  97.             expression="execution(* com.avicit..service..*.*(..))" />  
  98.         <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" />  
  99.     </aop:config>  
  100. </beans>  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值