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

    <!-- 该配置文件进行基本的Spring和Hibernate的集成配置。
          与业务相关的配置将放在其它的Spring配置文件中。 
    -->
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>WEB-INF/classes/conf.properties</value>
            </list>
        </property>
    </bean>
     
    <!-- 该 BeanPostProcessor 将自动起作用,对标注 @Autowired 的 Bean 进行自动注入 --> 
    <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
    <!-- 自动搜索路径 -->
    <context:component-scan base-package="com.agree" /> 
    
    
    <!-- 以下是应用的一些常用配置,包括数据源、 --> 
  <bean id="datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="${jdbc.driverClassName}" />
        <property name="jdbcUrl" value="${jdbc.url}" />
        <property name="user" value="${jdbc.username}"></property>
          <property name="password" value="${jdbc.password}"></property>
          <property name="minPoolSize"><value>3</value></property>
          <property name="maxPoolSize"><value>5</value></property>    <!--连接池中保留的最大连接数。Default: 15 --> 
          <property name="maxIdleTime"><value>10</value></property><!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 --> 
          <property name="acquireIncrement"><value>30</value></property>
          <property name="maxStatements"><value>0</value></property>
         <property name="initialPoolSize"><value>3</value></property><!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 --> 
          <property name="idleConnectionTestPeriod"><value>60</value></property><!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
          <property name="testConnectionOnCheckin"><value>false</value></property> 
          <property name="acquireRetryAttempts"><value>3</value></property><!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 --> 
        <property name="checkoutTimeout"><value>1000</value></property> <!--当连接池用完时客户端调用getConnection()后等待获取新连接的时间,超时后将抛出 SQLException,如设为0则无限期等待。单位毫秒。Default: 0 --> 
          <property name="breakAfterAcquireFailure"><value>false</value></property>
          <property name="testConnectionOnCheckout"><value>false</value></property>
    </bean>
     <!-- HIERNANATE配置 -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
       <property name="dataSource" ref="datasource"/>
       <property name="mappingResources">
               <list>
                    <value>cn/com/agree/domain/ProductVO.hbm.xml</value>
              </list>
        </property>
        <property name="hibernateProperties">
        <props>
             <prop key="hibernate.dialect">${hibernate.dialect}</prop>
              <prop key="hibernate.show_sql">true</prop>
               <prop key="hibernate.generate_statistics">true</prop>
             <prop key="hibernate.connection.release_mode">auto</prop>                      
               <prop key="hibernate.autoReconnect">true</prop>
               <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
               <prop key="hibernate.current_session_context_class">thread</prop>
               <prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>
               <!--使用二级缓存  -->
               <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
           </props>
       </property> 
    </bean>
    
    
    
    <!-- 配置数据库的事务管理器-->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
        <property name="sessionFactory"><ref bean="sessionFactory" /></property>
    </bean>
    <tx:advice id="txAdvice" transaction-manager="transactionManager" >
        <tx:attributes>
            <tx:method name="*" rollback-for="Exception"  propagation="REQUIRED" read-only="true"/>
        </tx:attributes>
    </tx:advice>
    <aop:config expose-proxy="true">  
        <!-- 只对业务逻辑层实施事务 -->  
        <aop:pointcut id="txPointcut" expression="execution(* cn.javass..service..*.*(..))" />  
        <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>  
    </aop:config>
    
    


    <bean id="habernateDao" class="cn.com.agree.dao.core.DbOperation">
        <property name="sessionFactory"><ref local="sessionFactory" /></property>
    </bean>
    
</beans>

 

posted on 2015-10-13 17:15  huadoumi  阅读(674)  评论(0编辑  收藏  举报

导航