Câu hỏi phỏng vấn Spring
Câu hỏi

What are Aspect, Advice, Po...

Câu trả lời

In Aspect-Oriented Programming (AOP), several key terminologies are essential to understand the framework, particularly when working with Spring AOP. These terms are Aspect, Advice, Pointcut, and JoinPoint. Here's a detailed explanation of each:

Aspect

An Aspect is a modularization of a concern that cuts across multiple classes. It is the unit of modularity similar to a class in Object-Oriented Programming (OOP). Aspects enable the encapsulation of behaviors affecting multiple classes into reusable modules. This encapsulation can include behaviors like transaction management, logging, or security features, which are typically scattered across several classes and methods. In Spring AOP, aspects are implemented using regular classes annotated with @Aspect or defined in an XML configuration[1][2][3].

Advice

Advice defines the action that an aspect takes at a particular join point. In other words, it is the actual code that is executed during the program execution by the AOP framework. There are several types of advice:

  • Before advice: Runs before the join point method execution.
  • After returning advice: Executes after the join point method completes normally.
  • After throwing advice: Executes if the method exits by throwing an exception.
  • After advice (also known as finally advice): Executes regardless of how the join point exits.
  • Around advice: Surrounds a join point such as a method invocation. This is the most powerful kind of advice because it can perform custom behavior before and after the method invocation, and it can even prevent the method from executing by not calling ProceedingJoinPoint.proceed()[1][2][3][5].

Pointcut

A Pointcut is a predicate or expression that matches join points, which are poin...

senior

senior

Gợi ý câu hỏi phỏng vấn

junior

What are ORM's Spring supports?

middle

What is Spring JDBCTemplate class and how to use it?

expert

What are some of the best practices for Spring Framework?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào