Ingeniero

Páginas: 77 (19093 palabras) Publicado: 30 de septiembre de 2012
Aspect Oriented Programming with Spring


Introduction

Aspect-Oriented Programming (AOP) complements
Object-Oriented Programming (OOP) by providing another way of thinking
about program structure. The key unit of modularity in OOP is the class,
whereas in AOP the unit of modularity is the aspect.
Aspects enable the modularization of concerns such astransaction
management that cut across multiple types and objects. (Such concerns are
often termed crosscutting concerns in AOP
literature.)

One of the key components of Spring is the AOP
framework. While the Spring IoC container does not depend on
AOP, meaning you do not need to use AOP if you don't want to, AOP
complements Spring IoC to provide a very capablemiddleware
solution.


Spring 2.0 AOP

Spring 2.0 introduces a simpler and more powerful way of writing
custom aspects using either a schema-based
approach or the @AspectJ annotation
style. Both of these styles offer fully typed advice and use of
the AspectJ pointcut language, while still using Spring AOP for
weaving.

The Spring2.0 schema- and @AspectJ-based AOP support is discussed
in this chapter. Spring 2.0 AOP remains fully backwards compatible with
Spring 1.2 AOP, and the lower-level AOP support offered by the Spring
1.2 APIs is discussed in the following
chapter.


AOP is used in the Spring Framework to...



... provide declarative enterpriseservices, especially as a
replacement for EJB declarative services. The most important such
service is declarative transaction
management.



... allow users to implement custom aspects, complementing their
use of OOP with AOP.



If you are interested only in generic declarative services
or other pre-packageddeclarative middleware services such as pooling, you
do not need to work directly with Spring AOP, and can skip most of this
chapter.


AOP concepts

Let us begin by defining some central AOP concepts and
terminology. These terms are not Spring-specific... unfortunately, AOP
terminology is not particularly intuitive; however, it would be even
moreconfusing if Spring used its own terminology.



Aspect: a modularization of a concern
that cuts across multiple classes. Transaction management is a good
example of a crosscutting concern in enterprise Java applications.
In Spring AOP, aspects are implemented using regular classes (the
schema-based approach) or regularclasses annotated with the @Aspect
annotation (the @AspectJ
style).



Join point: a point during the execution
of a program, such as the execution of a method or the handling of
an exception. In Spring AOP, a join point
always represents a method execution.



Advice: actiontaken by an aspect at a
particular join point. Different types of advice include "around,"
"before" and "after" advice. (Advice types are discussed below.)
Many AOP frameworks, including Spring, model an advice as an
interceptor, maintaining a chain of
interceptors around the join point.



Pointcut: a predicatethat matches join
points. Advice is associated with a pointcut expression and runs at
any join point matched by the pointcut (for example, the execution
of a method with a certain name). The concept of join points as
matched by pointcut expressions is central to AOP, and Spring uses
the AspectJ pointcut expression language by default....
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Ingeniero
  • Ingeniero
  • Ingeniero
  • Ingeniero
  • Ingeniero
  • Ingeniero
  • Ingeniero
  • Ingeniero

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS