Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding Spring AOP [closed]

I am working with Spring 3.0 framework and still a novice. Can anyone explain me in layman terms what is AOP programming? (a short example will definitely help)

How does Spring incorporate/enhance/support it?

like image 727
aces. Avatar asked Apr 08 '11 00:04

aces.


People also ask

How does AOP work in spring?

Spring AOP is proxy-based. Spring uses either JDK proxies (preferred wheneven the proxied target implements at least one interface) or CGLIB proxies (if the target object does not implement any interfaces) to create the proxy for a given target bean.

Is AOP still used in spring?

AOP is used in the Spring Framework to... ... provide declarative enterprise services, especially as a replacement for EJB declarative services. The most important such service is declarative transaction management.

What happens during weaving in AOP?

Weaving: linking aspects with other application types or objects to create an advised object. This can be done at compile time (using the AspectJ compiler, for example), load time, or at runtime.

What is Joinpoint in AOP?

Join Point: A join point is a specific point in the application such as method execution, exception handling, changing object variable values, etc. In Spring AOP a join point is always the execution of a method. Advice: Advices are actions taken for a particular join point.


1 Answers

AOP enables cohesive development by separation(module) of Cross Cutting Concerns into Aspects. Put it simple, it’s just an interceptor to intercept some processes, for example, when a method is execute, Spring AOP can hijack the executing method, and add extra functionality before or after the method execution.

For example: Logging, Transaction and security are some Aspects. In Logging we may have different aspect i.e. time calculation logging, simple in and out message logging and so on..

  • Advise defines what needs to be apply.
  • Joinpoint is where an Advice is apply.
  • Pointcut is a combination of different Jointpoints.
  • Aspect is applying an Advice at Pointcuts.

Note: Spring does not support AOP for methods marked as final.

enter image description here

Source


AOP works like Object Oriented Programming. In Object Oriented Programming, the unit of modularity is Object But in Aspect Oriented Programming the unit of modularity is Aspect. Aspect works as the modularization of concerns known as crosscutting concerns in AOP. AOP framework is pluggable in spring. AOP provides declarative enterprise service and allows users to implement custom aspects.

Source


Spring provides declarative programming with AOP. This is a better way to implement cross cutting concerns without the needs to use plumbing code all over the core business classes. AOP enables you to think about concerns or aspects in your system. Typical concerns are transaction management, logging etc. AOP enables you to capture the cross-cutting code in modules such as interceptors that can be applied declaratively wherever the concern they express applies. Spring includes a proxy-based AOP framework.

Source

like image 55
Premraj Avatar answered Sep 24 '22 01:09

Premraj