<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-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">
<context:annotation-config />
<context:component-scan base-package="com.eaglesoft" />
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl"
value="jdbc:mysql://localhost:3306/zsgl?characterEncoding=utf-8" />
<property name="user" value="root" />
<property name="password" value="123456" />
<!-- 指定连接池里最大连接数 -->
<property name="maxPoolSize" value="20" />
<!-- 指定连接池里最小连接数 -->
<property name="minPoolSize" value="1" />
<!-- 指定连接池里初始化连接数 -->
<property name="initialPoolSize" value="1" />
<!-- 指定连接池的连接的最大空闲时间 -->
<property name="maxIdleTime" value="20" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="packagesToScan">
<list>
<value>com.eaglesoft.model</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=true
javax.persistence.validation.mode=none
hibernate.connection.autocommit=false
<!-- connection.pool_size=1 -->
</value>
</property>
<!-- <property name="configLocation" value="classpath:hibernate.cfg.xml">
</property> -->
<!-- <property name="mappingResources"> <list> <value>com/test/model/Base_HY.hbm.xml</value>
</list> </property> <property name="packagesToScan"> <list> <value>com.test.model</value>
</list> </property> -->
</bean>
<bean id="egHibernateDaoSupport" class="com.eaglesoft.util.EgHibernateDaoSupport">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 配置Spring针对hibernate的事务管理器 -->
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 使用XML来使用事务管理-->
<aop:config>
<!-- 配置一个切面,和需要拦截的类和方法 -->
<aop:pointcut id="bussinessService" expression="execution(public * com.eaglesoft.service..*.*(..))" />
<aop:advisor pointcut-ref="bussinessService" advice-ref="txAdvice" />
</aop:config>
<!-- 配置一个事务通知 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="save" propagation="REQUIRED"/> <!-- 如果当前没有事务,就新建一个事务,如果已经存在一个事务中,加入到这个事务中。这是最常见的选择。 -->
<tx:method name="delete" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
</beans>
浙公网安备 33010602011771号