<?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: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-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!--配置文件导入 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:dataSource.properties</value>
</property>
</bean>
<!--数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${mysql.database.driver}"></property>
<property name="url" value="${mysql.database.url}"></property>
<property name="username" value="${mysql.database.user}"></property>
<property name="password" value="${mysql.database.password}"></property>
<property name="maxActive" value="${mysql.database.maxActive}"></property>
<property name="maxIdle" value="${mysql.database.maxIdle}"></property>
<property name="maxWait" value="${mysql.database.maxWait}"></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>org/usc/beans/Teacher.hbm.xml</value>
<value>org/usc/beans/Student.hbm.xml</value>
</list>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 那些类的哪些方法参与事务 -->
<aop:config>
<aop:pointcut id="allServiceMethod" expression="execution(* org.usc.daos.*.*.*(..))" />
<aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice" />
</aop:config>
<bean name="StudentService" class="org.usc.services.student.impl.StudentServiceBean">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean name="TeacherService" class="org.usc.services.teacher.impl.TeacherServiceBean">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean name="ListStudentAction" class="org.usc.actions.StudentListAction" scope="prototype">
<property name="studentService" ref="StudentService"></property>
</bean>
<bean name="ListTeacherAction" class="org.usc.actions.TeacherListAction" scope="prototype">
<property name="teacherService" ref="TeacherService"></property>
</bean>
</beans>
|