Java Reference
In-Depth Information
without ever starting up an application server. In fact, I often find that the only time
I need to use one is when developing code that uses a service such as JMS that is pro-
vided by the application server. Even when working on the presentation tier I'm
able to use a simpler web container such as Jetty. This is yet another example of how
lightweight frameworks make your life as a developer easier.
The role of AOP in the Spring framework
The technology underlying Spring's transaction management mechanism is
known as Aspect-Oriented Programming ( AOP ). AOP is a declarative mechanism
for changing the behavior of an application without requiring any modification to
the application itself. You write rules that specify new code to be executed when
methods are called and, in some cases, fields are accessed or objects instantiated.
In this example the BeanNameAutoProxyCreator arranged for the Transaction-
Interceptor to be executed whenever the TransferFacade was called without any
code changes. AOP is not limited to transaction management, and in this topic
you will see examples of interceptors that implement security, manage database
connections, and automatically retry transactions.
I'm using the Spring AOP implementation in this topic for the simple reason
that it provides the AOP interceptors for managing transactions, JDO , and Hiber-
nate connections. It is important to remember that the techniques described in this
book will work equally as well with other lightweight containers such as PicoCon-
tainer [PicoContainer], and other AOP mechanisms like AspectJ [Laddad 2003].
However, as of this writing, Spring provides the best implementation of the features
required by enterprise applications such as the Food to Go application, which is the
example application used throughout the rest of this topic.
The Spring framework is one example of a growing number of technologies
that are compelling alternatives to EJB s. Using Spring AOP provides the same ben-
efits of using EJB session beans but also allows you to use POJO s for your problem
domain. An EJB container provides a large number of services, including transac-
tion management. But is it worth compromising the design of the application to
take advantage of these services—especially if you can implement them using a
technology such as Spring in an Ă  la carte fashion?
1.2.6
Configuring applications with Spring
Most applications consist of multiple components that need to access one another.
A traditional J2EE application uses JNDI as the mechanism that one component
uses to access another. For example, the presentation tier uses a JNDI lookup to
obtain a reference to a session bean home interface. Similarly, an EJB uses JNDI to
 
 
 
 
 
 
 
 
Search WWH ::




Custom Search