<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
		<property name="driverClass">
			<value>com.mysql.jdbc.Driver</value>
		</property>
		<property name="jdbcUrl">
		     <value>jdbc:mysql://localhost/microblog</value> 
		</property>
		<property name="user">
			<value>root</value>
		</property>
		<property name="password">
			<value>123456</value>
		</property>
		<property name="maxPoolSize">
			<value>80</value>
		</property>
		<property name="minPoolSize">
			<value>1</value>
		</property>
		<property name="initialPoolSize">
			<value>1</value>
		</property>
		<property name="maxIdleTime">
			<value>20</value>
		</property>
	</bean>

	<!--定义了Hibernate的SessionFactory -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource">
			<ref local="dataSource" />
		</property>
		<property name="mappingResources">
			<list>
				<value>com/itjob/dao/model/User.hbm.xml</value>
				<value>com/itjob/dao/model/TRight.hbm.xml</value>
				<value>com/itjob/dao/model/Role.hbm.xml</value>
			</list>
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
				<prop key="show_sql">true</prop>
				<prop key="hibernate.jdbc.batch_size">20</prop>
			</props>
		</property>
	</bean>

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

	<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
		<!--  事务拦截器bean需要依赖注入一个事务管理器 -->
		<property name="transactionManager" ref="transactionManager" />
		<property name="transactionAttributes">
			<!--  下面定义事务传播属性-->
			<props>
				<prop key="save*">PROPAGATION_REQUIRED</prop>
       			<prop key="update*">PROPAGATION_REQUIRED</prop>
        		<prop key="delete*">PROPAGATION_REQUIRED</prop>
        		<prop key="login*">PROPAGATION_REQUIRED</prop>
        		<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
        		<prop key="*">PROPAGATION_REQUIRED</prop>
			</props>
		</property>
	</bean>

	<!-- 定义BeanNameAutoProxyCreator-->
	<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<!--  指定对满足哪些bean name的bean自动生成业务代理 -->
		<property name="beanNames">
			<list>
				<!--  需要自动创建事务代理的bean-->
				<value>userManager</value>
				<value>rightManager</value>
				<value>roleManager</value>
			</list>
			<!--  此处可增加其他需要自动创建事务代理的bean-->
		</property>
		<!--  下面定义BeanNameAutoProxyCreator所需的事务拦截器-->
		<property name="interceptorNames">
			<list>
				<value>transactionInterceptor</value>
			</list>
		</property>
	</bean>

	<bean id="baseDao" class="com.itjob.dao.BaseDaoImpl">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>
	
	<!--用户信息管理业务逻辑类 -->
	<bean id="userManager" class="com.itjob.service.UserManagerImpl">
		<property name="dao">
			<ref bean="baseDao" />
		</property>
	</bean>
	
	<!--权限信息管理业务逻辑类 -->
	<bean id="rightManager" class="com.itjob.service.RightManagerImpl">
		<property name="dao">
			<ref bean="baseDao" />
		</property>
	</bean>
	
	<!--角色信息管理业务逻辑类 -->
	<bean id="roleManager" class="com.itjob.service.RoleManagerImpl">
		<property name="dao">
			<ref bean="baseDao" />
		</property>
	</bean>
</beans>
