<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
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.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- 引入配置文件 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
lazy-init="false">
<property name="locations">
<list>
<value>classpath:conf/proxool.properties</value>
</list>
</property>
</bean>
<!-- proxool連接池數據源配置 -->
<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource"
p:alias="${proxool.alias}"
p:driver="${proxool.driver-class}"
p:driverUrl="${proxool.driver-url}"
p:user="${proxool.user}"
p:password="${proxool.password}"
p:maximumConnectionCount="${proxool.maximum-connection-count}"
p:minimumConnectionCount="${proxool.minimum-connection-count}"
p:prototypeCount="${proxool.prototype-count}"
p:testBeforeUse="${proxool.test-before-use}"
p:houseKeepingTestSql="${proxool.house-keeping-test-sql}"/>
<!-- hibernate SessionFactory配置 -->
<!-- org.springframework.orm.hibernate3.LocalSessionFactoryBean -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
<prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>com.cb.entity</value>
</list>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/cb/entity/hbm/</value>
</list>
</property>
</bean>
<!-- 自動裝配Bean -->
<context:component-scan base-package="com.cb.service.impl"/>
<!-- 事物配置 -->
<bean id="transManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<!-- 配置哪些方法需要事物 -->
<tx:advice id="txAdvice" transaction-manager="transManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="del*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="update*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 配置哪些方法需要事務管理 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(* com.cb.service.impl.*.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
</aop:config>
</beans>
支持hibernate註解和xml共存的Spring配置
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.