Home  >  Spring Interview Q & A

Interview Questions: Aspect Oriented Programming (AOP)

June 12, 2013
Qns-1: What is Aspect Oriented Programming (AOP) in Spring?
Ans: Aspect Oriented Programming 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.
Qns-2: Define AOP terminologies in Spring.
Ans: Aspect: In multiple classes, the modularization of concerns that acts as crosscutting concerns. Example – Transaction management
Join Point: Join Point is a point during the execution of the method.
Advice: At a join point, the action taken by aspect is Advice.
Pointcut: Those predicates which matches join point is called Pointcut.
Weaving: Other application type can be linked with aspect and that is known as weaving.
Introduction: Introduction is defining additional methods fields for a type.
Target object: Those objects which are advised by aspects are Target Object.
AOP proxy: AOP framework creates an object to meet aspect contract, that object is AOP proxy.
Qns-3: Define the types of advice in Spring AOP.
Ans: In Spring AOP, types of advice are
Before: Advice that runs before a join point.
After returning: Advice that runs after a join point normal completion.
After throwing: Advice which runs when a methods exits by throwing an exception.
After: Advice that runs after the join point exit by any way.
Around: Advice that runs surrounding to join point. Example – method invocation.
Qns-4: How to enable @AspectJ Support?
Ans: Include the below XML code in application XML
Qns-5: How to declare aspect in Spring AOP?
Ans: Find the below XML snippet
<bean id="myAspect" class="com.concretepage.MyAspect">
   <!-- configure properties of aspect here -->

Qns-6: How to declare a pointcut in Spring AOP?
Ans: Find the below code snippet.
@Pointcut("execution(* update(..))")
private void accountUpdate {}
Qns-7: What are the supported AspectJ pointcut designators in Spring AOP?
Ans: Followings are the AspectJ pointcut designators in Spring AOP. Execution
Qns-8: When to use Spring AOP and when to use full AspectJ?
Ans: If we only need to advice the execution of operations on Spring beans then we should use Spring AOP. Spring AOP is simpler than AspectJ. Full AspectJ requires the AspectJ complier in the build process.
In case if we advice objects not to be managed by Spring Container, use AspectJ.
Qns-9: What do you understand by Load-time weaving (LTW) in Spring?
Ans: Load-time weaving (LTW) is a process of weaving AspectJ aspects into an application’s class file when the classes are being loaded in JVM.
Qns-10: What are the required libraries to run AspectJ LTW in Spring?
a. spring-aop.jar
b. aspectjrt.jar
c. aspectjweaver.jar

©2022 concretepage.com | Privacy Policy | Contact Us