Java Reference
In-Depth Information
Table 11.1
A comparison of Spring and Blueprint XML syntax
(continued)
Element/Attribute meaning
Spring syntax
Blueprint syntax
Exposing a service
<service>
<service>
Consuming a single service
<reference>
<reference>
Consuming multiple services
<list>
<reference-list>
SPRING TRANSACTIONS
In addition to its dependency injection model, Spring offers declarative transaction
support to beans using aspect-oriented programming. This can be a little complicated
to configure, but typically you would use one of Spring's predefined transaction
aspects with a Spring transaction manager. A simple example might look like the
XML
in the following listing.
Listing 11.5
Controlling transactions with Spring
<?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: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/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">
B
Intercept all methods in
fancyfoods.persistence
<aop:config>
<aop:pointcut id="requiredTxBeans"
expression="execution(* fancyfoods.persistence.*.*(..))"/>
<aop:advisor pointcut-ref="requiredTxBeans"
advice-ref="requiredTxAdvice"/>
</aop:config>
<tx:advice id="requiredTxAdvice">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
C
Require transaction
for all methods
D
Bean will be
transactional
<bean id="inventory"
class="fancyfoods.persistence.InventoryImpl"/>
</beans>
The
XML
in listing 11.5 defines a number of things. In
B
it defines the locations into
which the transaction aspect should be injected. The aspect itself is defined at
C
, and
declares that this injection point should create a transaction if none exists already.
Finally, you can see the declaration of the bean itself at
D
.

















