Spring 声明式事务管理 xml配置的配置文件
Spring声明式事务管理,采用xml配置的配置文件如下:
<?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:aop="http://www.springframework.org/schema/aop"xmlns:context="http://www.springframework.org/schema/context" 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/aop http://www.springframework.org/schema/aop/spring-aop-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/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"><!-- 打开Annotation注入 --><context:annotation-config /><context:component-scan base-package="com.spring" /><beandestroy-method="close"value="${jdbc.driverClassName}" /><property name="url" value="${jdbc.url}" /><property name="username" value="${jdbc.username}" /><property name="password" value="${jdbc.password}" /></bean><bean id="sessionFactory"ref="dataSource" /><property name="annotatedClasses"><list><value>com.spring.model.User</value><value>com.spring.model.Log</value></list></property><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><prop key="hibernate.show_sql">true</prop></props></property></bean><!--the transactional advice (what 'happens'; see the <aop:advisor/> beanbelow)--><tx:advice id="txAdvice" transaction-manager="txManager"><tx:attributes><!--all methods starting with 'get' are read-only调用readOnly的Connection,以提高性能--><tx:method name="get*" read-only="true" /><!-- other methods use the default transaction settings (see below) --><tx:method name="sa*" propagation="REQUIRED" /></tx:attributes></tx:advice><!--ensure that the above transactional advice runs for any execution ofan operation defined by the FooService interface--><aop:config><!-- 定义一个切面 --><aop:pointcut id="bussinessPointcut"expression="execution(public * com.spring..*.*(..))" /><!--定义一个建议者 即对于满足bussinessPointcut这个条件的方法方法提供txAdvice建议--><aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessPointcut" /></aop:config><!--a PlatformTransactionManager is still required 定义了一个事务管理器--><bean id="txManager"ref="sessionFactory" /></bean></beans>