Java Reference
In-Depth Information
<beans xmlns= " http://www.springframework.org/schema/beans "
xmlns:xsi= " http://www.w3.org/2001/XMLSchema-instance "
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-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/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd " >
<tx:advice id= " bookShopTxAdvice "
transaction-manager= " transactionManager " >
<tx:attributes>
<tx:method name= " purchase " />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id= " bookShopOperation " expression=
" execution(* com.apress.springenterpriserecipes.bookshop.spring.
BookShop.*(..)) " />
<aop:advisor advice-ref= " bookShopTxAdvice "
pointcut-ref= " bookShopOperation " />
</aop:config>
...
<bean id= " transactionManager "
class= " org.springframework.jdbc.datasource.DataSourceTransactionManager " >
<property name= " dataSource " ref= " dataSource " />
</bean>
<bean id= " bookShop "
class= " com.apress.springenterpriserecipes.bookshop.spring.JdbcBookShop " >
<property name= " dataSource " ref= " dataSource " />
</bean>
</beans>
The preceding AspectJ pointcut expression matches all the methods declared in the BookShop
interface. However, because Spring AOP is based on proxies, it can apply only to public methods. Thus
only public methods can be made transactional with Spring AOP.
Each transaction advice requires an identifier and a reference to a transaction manager in the IoC
container. If you don't specify a transaction manager explicitly, Spring will search the application
context for a TransactionManager with a bean name of transactionManager . The methods that require
transaction management are specified with multiple <tx:method> elements inside the <tx:attributes>
element. The method name supports wildcards for you to match a group of methods. You can also
define transaction attributes for each group of methods, but let's use the default attributes for
simplicity's sake. The defaults are shown in Table 4-5.
Search WWH ::




Custom Search