电子商务网站的Spring+hibernate配置文件(AOP事务)

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

<!-- 数据源定义,使用Apache DBCP 连接池 -->
<bean id="baseDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
   <property name="driverClassName" value="${jdbc.driverClassName}"/>
   <property name="url" value="${jdbc.url}"/>
   <property name="username" value="${jdbc.username}"/>
   <property name="password" value="${jdbc.password}"/>
   <property name="maxActive" value="${manage.datasource.maxActive}" />
   <property name="maxIdle" value="30" />
   <property name="maxWait" value="1000" />
   <property name="defaultAutoCommit" value="true" />
   <property name="removeAbandoned" value="true" />
   <property name="removeAbandonedTimeout" value="60" />
   <property name="validationQuery" value="select 1 "/>
   <property name="testOnBorrow" value="true"/>
</bean>

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>

<!-- applicationContext.xml -->
<!-- 属性文件读入 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="locations">
    <list>
     <value>classpath*:config/jdbc.properties</value>
     <value>classpath*:config/hibernate.properties</value>
     <value>classpath*:config/manage-config.properties</value>
    </list>
   </property>
</bean>

<!-- 支持 @Transactional 标记 -->
<tx:annotation-driven/>

<!-- 支持 @AspectJ 标记-->
<aop:aspectj-autoproxy/>

<!-- 以AspectJ方式 定义 AOP -->
<aop:config proxy-target-class="true">
   <aop:advisor pointcut="execution(* com.sitechasia.webshop..*ServiceImpl.*(..))"
      advice-ref="txAdvice"/>
</aop:config>

<!-- 基本事务定义,使用transactionManager作事务管理,默认get*方法的事务为readonly,其余方法按默认设置.
    默认的设置请参考Spring文档事务一章. -->
<tx:advice id="txAdvice">
   <tx:attributes>
    <tx:method name="get*" read-only="true" />
    <tx:method name="find*" read-only="true" />
    <tx:method name="load*" read-only="true" />
    <tx:method name="search*" read-only="true" />
    <tx:method name="*" propagation="REQUIRED"/>
   </tx:attributes>
</tx:advice>

<!--多数据源配置 -->
<!--
<aop:config proxy-target-class="true">
   <aop:advisor pointcut="execution(* javax.sql.DataSource.getConnection(..))"
      advice-ref="connectionInterceptor"/>
</aop:config>
<bean id="connectionInterceptor" class="com.sitechasia.webshop.common.persistence.ConnectionInterceptor">
    <property name="excludes" >
     <list>
      <value>${commondb.common}</value>    
     </list>
    </property>
</bean>
-->
<bean id="cacheConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="locations">
    <list>
     <value>classpath*:config/cache.properties</value>
    </list>
   </property>
   <property name="placeholderPrefix" value="#{"/>
    </bean>

<!-- dataAcessContext-hibernate.xml -->
<bean id="dataSource" parent ="baseDataSource"/>

<bean id="databaseMapping" class=" com.sitechasia.webshop.common.persistence.DomainDatabaseMapping">
</bean>
<bean id="webshopDS" class="com.sitechasia.webshop.common.persistence.MultiDataSource">
   <property name="dataSource" ref="dataSource"/>
   <property name="databaseMapping" ref="databaseMapping"/>
</bean>
<!--Hibernate SessionFatory-->

<bean id="sessionFactory" class="com.sitechasia.webx.core.dao.hibernate3.NamedMoudleHbmLocalSessionFactoryBean">
   <property name="dataSource" ref="webshopDS"/>
   <property name="configLocations">
    <list>
    </list>
   </property>
   <property name="hibernateProperties">
    <props>
     <prop key="hibernate.dialect">${hibernate.dialect}</prop>
     <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
     <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
     <prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
     <prop key="hibernate.connection.release_mode">${hibernate.connection.release_mode}</prop>
       <prop key="memcached.servers">#{memcached.servers}</prop>
     <prop key="memcached.failover">#{memcached.failover}</prop>
     <prop key="memcached.initConn">#{memcached.initConn}</prop>
     <prop key="memcached.minConn">#{memcached.minConn}</prop>
     <prop key="memcached.maxConn">#{memcached.maxConn}</prop>
     <prop key="memcached.maintSleep">#{memcached.maintSleep}</prop>
     <prop key="memcached.nagle">#{memcached.nagle}</prop>
     <prop key="memcached.socketTO">#{memcached.socketTO}</prop>
     <prop key="memcached.aliveCheck">#{memcached.aliveCheck}</prop>
    </props>
   </property>
   <property name="mappingResourceServices">
     <value>true</value>
   </property>
</bean>

<!--Hibernate TransactionManager-->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
   <property name="sessionFactory" ref="sessionFactory"/>
</bean>


<!-- for common db -->
<bean id="baseDSDBCP2" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
   <property name="driverClassName" value="${commondb.jdbc.driverClassName}" />
   <property name="url" value="${commondb.jdbc.url}" />
   <property name="username" value="${commondb.jdbc.username}" />
   <property name="password" value="${commondb.jdbc.password}" />
   <property name="maxActive" value="${manage.commonDatasource.maxActive}" />
   <property name="maxIdle" value="30" />
   <property name="maxWait" value="1000" />
   <property name="defaultAutoCommit" value="true" />
   <property name="removeAbandoned" value="true" />
   <property name="removeAbandonedTimeout" value="60" />
   <property name="validationQuery" value="select 1 "/>
   <property name="testOnBorrow" value="true"/>
</bean>
<bean id="baseDataSource2" class="com.sitechasia.webx.components.datasource.proxy.BeanModeDomainAwareDataSource">
   <property name="defaultDataSource" ref="baseDSDBCP2" />
</bean>

<bean id="commonDS" parent="baseDataSource2"/>

<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
   <property name="applicationContextSchedulerContextKey">
     <value>applicationContext</value>
    </property>
    <property name="dataSource">
     <ref bean="commonDS"/>
    </property>
    <property name="autoStartup" value="${ProductMode}"/>
</bean>

<!-- Transaction Interceptor set up to do PROPOGATION_REQUIRED on all methods -->
<bean id="matchAllTxInterceptor2" class="org.springframework.transaction.interceptor.TransactionInterceptor">
   <property name="transactionManager">
    <ref bean="transactionManager2" />
   </property>
   <property name="transactionAttributes">
    <props>
     <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
     <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
     <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
     <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
   </property>
</bean>

<bean id="autoProxyCreator2" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
   <property name="interceptorNames">
    <list>
     <idref local="matchAllTxInterceptor2" />
    </list>
   </property>
   <property name="proxyTargetClass">
    <value>true</value>
   </property>
   <property name="beanNames">
    <list>
     <value>com.sitechasia.webshop.rsscommon.service.**</value>    
    </list>
   </property>
</bean>

  
<!--Hibernate SessionFatory-->
<bean id="sessionFactory2" class="com.sitechasia.webx.core.dao.hibernate3.NamedMoudleHbmLocalSessionFactoryBean">
   <property name="dataSource" ref="commonDS" />
   <property name="mappingResources">
    <list>
     <value>modules/rsscommon/hibernate-conf/DsRssSourceDO.hbm.xml</value>
     <value>modules/rsscommon/hibernate-conf/RssSource.hbm.xml</value>
     <value>modules/rsscommon/hibernate-conf/RssInfo.hbm.xml</value>
    </list>
   </property>
   <property name="hibernateProperties">
    <props>
     <prop key="hibernate.dialect">${commondb.hibernate.dialect}</prop>
     <prop key="hibernate.show_sql">${commondb.hibernate.show_sql}</prop>
     <prop key="hibernate.cache.use_query_cache">${commondb.hibernate.cache.use_query_cache}</prop>
     <prop key="hibernate.cache.provider_class">${commondb.hibernate.cache.provider_class}</prop>
       <prop key="memcached.servers">#{memcached.servers}</prop>
     <prop key="memcached.failover">#{memcached.failover}</prop>
     <prop key="memcached.initConn">#{memcached.initConn}</prop>
     <prop key="memcached.minConn">#{memcached.minConn}</prop>
     <prop key="memcached.maxConn">#{memcached.maxConn}</prop>
     <prop key="memcached.maintSleep">#{memcached.maintSleep}</prop>
     <prop key="memcached.nagle">#{memcached.nagle}</prop>
     <prop key="memcached.socketTO">#{memcached.socketTO}</prop>
     <prop key="memcached.aliveCheck">#{memcached.aliveCheck}</prop>
    </props>
   </property>
   <property name="mappingResourceServices">
    <value>false</value>
   </property>
</bean>

<!--Hibernate TransactionManager-->
<bean id="transactionManager2"          class="org.springframework.orm.hibernate3.HibernateTransactionManager">
   <property name="sessionFactory" ref="sessionFactory2" />
</bean>
</beans>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值