A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

What is Spring AOP?

Spring AOP


Spring AOP is the feature of Spring Framework that provides modularity in aspect rather than class.
·       AOP breakdowns the program logic into different parts (that is called concerns).
·       Its compliments OOPs. Since AOP and OOPS both provide modularity, but the key unit of modularity is aspect than class.
·       crosscutting concern is a concern that can touch the entire application such as authentication, logging, security, transaction management etc.
·       In spring, AOP is method level, not class level.
·       AspectJ is similar to AOP but it is more flexible and powerful.
·       Spring AOP (Aspect-oriented programming) framework, is used to modularize crosscutting concerns in aspects.
·       In very simple word, we can say that when a method is going to execute, Spring AOP can take over the executing method, and add additional functionality before or after the method execution.
·       The most common usage is where your application has cross-cutting concerns i.e. a piece of logic or code that is going to be written in multiple classes/layers.

There is four type of advice in Spring AOP. Let us understand these concepts:
  • Before advice – Run before the method execution
  • After returning advice – Run after the method returns a result
  • After throwing advice – Run after the method throws an exception
  • Around advice – Run around the method execution, combine all three advices above.


What is the most common use for AOP in spring project?


AOP can be used in the following cases:
·       AOP can provide declarative enterprise services such as declarative transaction management.
·       The most common use is probably the declarative transaction handling using @Transactional
·       It allows users to implement custom aspects.

·       Piece of logic or code that is going to be written in multiple classes/layers. Some very common examples are Transaction Management, Logging, Exception Handling, Security aspects and Instrumentation.














LEARN TUTORIALS

.

.