<?xml version="1.0" encoding="UTF-8"?>
<!-- Application context definition for PetClinic on Hibernate. -->
<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: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.xsd
			http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
			http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
			http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

	<!-- 装载属性配置文件 -->
	<!-- <bean id="propertyConfig"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations" value="classpath:jdbc.properties">
		</property>
	</bean> -->

	<!-- 配置数据源 -->
	<bean id="dataSource"
		class="org.apache.commons.dbcp2.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="initialSize" value="3" />
		<property name="minIdle" value="3" />
		<property name="maxIdle" value="5" />
		<property name="maxTotal" value="15" />
		<property name="timeBetweenEvictionRunsMillis" value="1000" />
		<property name="validationQuery" value="select 1" />
	</bean>

	<bean id="sf"
		class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation" value="classpath:hibernate.cfg.xml" />
		<property name="hibernateProperties">

			<props>
				<prop key=""></prop>
				<prop key="connection.autocommit">true</prop>
			</props>
		</property>
	</bean>


	<!-- 配置事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate5.HibernateTransactionManager">
		<property name="sessionFactory" ref="sf" />


	</bean>

	<aop:config>
		<aop:pointcut id="allDaoMethod"
			expression="execution(* com.lerx.dao.impl.*.*(..))" />
		<aop:advisor pointcut-ref="allDaoMethod"
			advice-ref="txAdvice" />
	</aop:config>

	<tx:advice id="txAdvice"
		transaction-manager="transactionManager">

		<tx:attributes>

			<tx:method name="add*" propagation="REQUIRED" />
			<tx:method name="del*" propagation="REQUIRED" />
			<tx:method name="undel*" propagation="REQUIRED" />
			<tx:method name="modify*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="move*" propagation="REQUIRED" />
			<tx:method name="set*" propagation="REQUIRED" />
			<tx:method name="login*" propagation="REQUIRED" />
			<tx:method name="excute*" propagation="REQUIRED" />
			<tx:method name="*_update" propagation="REQUIRED" />

			<tx:method name="*" read-only="true" propagation="REQUIRED" />

		</tx:attributes>
	</tx:advice>
	
	<context:component-scan
		base-package="com.lerx.handlers">
		<context:include-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
	</context:component-scan>


</beans>
