<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd "
>
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
abstract="false" lazy-init="default" autowire="default"
dependency-check="default">
<!-- -->
expression="execution(* com.service.*.*(..))" />
pointcut-ref="allManagerMethod" />
另外一个例子的配置如下:
<?xml version="1.0" encoding="UTF-8"?>
"http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-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
">
"com.sxt"/>
<!-- 支持aop注解 -->
"dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
"driverClassName"
value="com.mysql.jdbc.Driver">
"url" value="jdbc:mysql://localhost:3306/myhib">
"username" value="root">
"password" value="123456">
"sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
"dataSource">
"dataSource" />
"hibernateProperties">
<!-- key的名字前面都要加hibernate. -->
"hibernate.dialect">
org.hibernate.dialect.MySQLDialect
"hibernate.show_sql">true
"hibernate.hbm2ddl.auto">update
"packagesToScan">
com.sxt.po
"hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate" >
"sessionFactory" ref="sessionFactory">
<!--配置一个JdbcTemplate实例-->
"jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
"dataSource" ref="dataSource"/>
<!-- 配置事务管理 -->
"txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
"sessionFactory" ref="sessionFactory">
"txManager" />
"execution(public * com.sxt.service.impl.*.*(..))" id="businessService"/>
"txAdvice" pointcut-ref="businessService" />
"txAdvice" transaction-manager="txManager" >
"find*" read-only="true" propagation="NOT_SUPPORTED" />
<!-- get开头的方法不需要在事务中运行 。
有些情况是没有必要使用事务的,比如获取数据。开启事务本身对性能是有一定的影响的-->
"*"/> <!-- 其他方法在实务中运行 -->