Spring AOP (Aspect-Oriented Programming) Interview Questions and Answers
1. What is the concept of AOP?
Aspect-oriented programming (AOP) is an approach to programming that sanctions the global properties of a program to determine how it is compiled into an executable program. AOP can be utilized with object-oriented programming (OOP). An aspect is a subprogram that is associated with a specific property of a program.
More Java interview questions and answers...- Spring Boot actuator interview questions and answers
- Spring Core - Interview Questions
- Top Spring Cloud Interview Questions
- Spring Security Interview Questions
- Spring MVC - Interview Questions
- Spring Webflux Interview Questions
- Top Spring Boot Interview Questions
- Spring Data JPA Interview Questions and Answers
- Top Mockito Interview Questions and Answers
- Java Collections Interview Questions
- Java Stream API Interview Questions and Answers - Frequently asked
- Quarkus - Interview questions and answers
- Spring Interview questions and answers
- Spring Boot actuator interview questions and answers
- Spring Core - Interview Questions
- Top Spring Cloud Interview Questions
- Spring Security Interview Questions
- Spring MVC - Interview Questions
- Spring Webflux Interview Questions
- Top Spring Boot Interview Questions
- Spring Data JPA Interview Questions and Answers
- Top Mockito Interview Questions and Answers
- Java Collections Interview Questions
- Java Stream API Interview Questions and Answers - Frequently asked
- Quarkus - Interview questions and answers
- Spring Interview questions and answers
2. Why do we use AOP?
- Reduced code clutter
- Truncated code redundancy
- More facile code maintenance
- More expeditious development
- Amended code readability
3. What is Spring AOP used for?
Spring AOP enables Aspect-Oriented Programming in spring applications. In AOP, aspects enable the modularization of concerns such as transaction management, logging, or security that cut across multiple types and objects.
4. What is advice, joinpoint, and pointcut?
JoinPoint: Joinpoint are points in our program execution where the flow of execution changed like Exception catching and calling other methods.
PointCut: PointCut are fundamentally those Joinpoints where we can put our advice(or call aspect).
Advice: This is an object which includes API invocations to the system-wide concerns representing the action to perform at a joinpoint designated by a point.
5. What are the types of Advice in Spring AOP?
In Spring AOP, 5 type of advices are fortified :
- 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, cumulate all three advices above.
- Finally advice. Advice that is executed irrespective of how a joinpoint exits.
6. What is the Target object in Spring AOP?
The target object is an object being advised by one or more aspects. It will always be a proxy object. It is additionally referred to as the advised object.
7. What is a Proxy in Spring AOP?
AOP proxy is an object engendered by the AOP framework in order to implement the aspect contracts. In the Spring Framework, an AOP proxy will be a JDK dynamic proxy or a CGLIB proxy.
8. What are the different types of AutoProxying in Spring AOP?
- BeanNameAutoProxyCreator
- DefaultAdvisorAutoProxyCreator
- Metadata autoproxying
9. What is weaving in Spring AOP?
This is the process of inserting aspects into the application code at the appropriate point.
10. Which design pattern is used in Spring AOP?
Proxy - used heavily in AOP and remoting.
Singleton - beans defined in spring config files are singletons.
The template method is used extensively to deal with repeated boilerplate code.
11. What is @aspect annotation in spring boot?
An aspect can be engendered in spring boot with help of @Aspect annotation and registering with bean container with @Component annotation. Inside the aspect class, we can engender advices as required.
12. What are the two types of implementing Spring AOP?
- Using XML configuration files
For Example, Declaring an aspect:
<aop:config>
<aop:aspect id="myAspect" ref="myBean">
...
</aop:aspect>
</aop:config>
<bean id="myBean" class="...">
...
</bean>
- Using AspectJ annotation style
For Example, Declaring an aspect:
import org.aspectj.lang.annotation.Aspect;
@Aspect
public class MyAspect {
}
More Java interview questions and answers...- Spring Boot actuator interview questions and answers
- Spring Core - Interview Questions
- Top Spring Cloud Interview Questions
- Spring Security Interview Questions
- Spring MVC - Interview Questions
- Spring Webflux Interview Questions
- Top Spring Boot Interview Questions
- Spring Data JPA Interview Questions and Answers
- Top Mockito Interview Questions and Answers
- Java Collections Interview Questions
- Java Stream API Interview Questions and Answers - Frequently asked
- Quarkus - Interview questions and answers
- Spring Interview questions and answers
- Spring Boot actuator interview questions and answers
- Spring Core - Interview Questions
- Top Spring Cloud Interview Questions
- Spring Security Interview Questions
- Spring MVC - Interview Questions
- Spring Webflux Interview Questions
- Top Spring Boot Interview Questions
- Spring Data JPA Interview Questions and Answers
- Top Mockito Interview Questions and Answers
- Java Collections Interview Questions
- Java Stream API Interview Questions and Answers - Frequently asked
- Quarkus - Interview questions and answers
- Spring Interview questions and answers