Spring Aop Interview Questions & Answers

4 avg. rating (80% score) - 5879 votes

Spring Aop Interview Questions & Answers

Are you looking for spring Aop job? Need interview questions for preparation? Here’s the perfect solution for your queries. Find the spring Aop job interview questions and answers on wisdom jobs career edge for your interview success. Aspect Oriented Programming (AOP) is offers modularity. Spring framework has various examples like logging, auditing, declarative transactions, security, caching, etc. Various spring AOP jobs include sr.java developer, java micro service developer,java&spark developer,core java spark developer, automation developer, solution architect, java full stack developer, java teamlead,senior java developer MVC/Spring,JSF developer, java consultant, spring /hibernate framework developer etc. Having experience on Java along with Application framework i.e. Spring and Hibernate will help you to gain an edge in your career path. Search and apply jobs on wisdom jobs now!

Spring Aop Interview Questions

Spring Aop Interview Questions
    1. Question 1. What Is A Pointcut, A Join Point, An Advice, An Aspect, Weaving, Introduction, Target Object, Aop Proxy?

      Answer :


      An expression that selects one or more Join Points

      Join Point

      A point in the execution of a program such as a method call or exception thrown


      Code to be executed at each selected Join Point


      A module that encapsulates pointcuts and advice


      Technique by which aspects are combined with main code


      Spring AOP allows to introduce new interfaces (and a corresponding application) to any object advises. 

      Target Object

      An object is assisted by one or more respects. Also known as the object advised. 

      AOP Proxy

      AOP proxy is an object used to perform the contract area. This object is created by the AOP framework. In Spring AOP proxy is part of JDK dynamic proxy or proxy CGLIB.

    2. Question 2. How Does Spring Solve (implement) A Cross Cutting Concern?

      Answer :

      Implement your mainline application logic:

      • Focusing on the core problem
      • Write aspects to implement your cross-cutting concerns
      • Spring provides many aspects out-of-the-box Weave the aspects into your application
      • Adding the cross-cutting behaviors to the right places.

    3. Question 3. Which Are The Limitations Of The Two Proxy-types?

      Answer :

      Spring will create either JDK or CGLib proxies

      JDK Proxy

      • Also called dynamic proxies
      • API is built into the JDK
      • Requirements: Java interface(s)
      • All interfaces proxied

      CGLib Proxy

      • NOT built into JDK
      • Included in Spring jars
      • Used when interface not available
      • Cannot be applied to final classes or method

    4. Question 4. How Many Advice Types Does Spring Support. What Are They Used For?

      Answer :

      Before advice: Advice that executes before a join point, but which does not have the ability to prevent execution flow proceeding to the join point (unless it throws an exception).

      After returning advice: Advice to be executed after a join point completes normally: for example, if a method returns without throwing an exception.

      After throwing advice: Advice to be executed if a method exits by throwing an exception.

      After advice: Advice to be executed regardless of the means by which a join point exits (normal or exceptional return).

      Around advice: Advice that surrounds a join point such as a method invocation. This is the most powerful kind of advice. Around advice can perform custom behavior before and after the method invocation. It is also responsible for choosing whether to proceed to the join point or to shortcut the advised method execution by returning its own return value or throwing an exception.

    5. Question 5. What Do You Have To Do To Enable The Detection Of The @aspect Annotation?

      Answer :

      To use @AspectJ aspects in a Spring configuration you need to enable Spring support for configuring Spring AOP based on @AspectJ aspects, and autoproxying beans based on whether or not they are advised by those aspects.

      Enabling @AspectJ Support with Java configuration

      To enable @AspectJ support with Java @Configuration add the @EnableAspectJAutoProxy annotation:



      public class AppConfig {


      Enabling @AspectJ Support with XML configuration

      To enable @AspectJ support with XML based configuration use the <aop:aspectj-autoproxy/> element:


    6. Question 6. Name Three Typical Cross Cutting Concerns?

      Answer :

      1. Logging
      2. Security
      3. Transaction

    7. Question 7. What Does @enableaspectjautoproxy Do?

      Answer :

      To enable @AspectJ support with Java @Configuration add the @EnableAspectJAutoProxy annotation:



      public class AppConfig {


    8. Question 8. What Is A Named Pointcut?

      Answer :

      A named pointcut can be declared inside an <aop:config> element, enabling the pointcut definition to be shared across several aspects and advisors.


          <aop:pointcut id="businessService" expression="execution(* com.xyz.myapp.service.*.*(..))"/>


    9. Question 9. How Do You Externalize Pointcuts? What Is The Advantage Of Doing This?

      Answer :

      Externalize the pointcut to a named pointcut. Avoid to writing complex pointcut expression across the application.

    10. Question 10. What Is The Joinpoint Argument Used For?

      Answer :

      Context provided by the JoinPoint parameter and Context about the intercepted point.

    11. Question 11. What Is A Proceedingjoinpoint?

      Answer :

      An around advice is a special advice that can control when and if a method (or other join point) is executed. This is true for around advices only, so they require an argument of type ProceedingJoinPoint, whereas other advices just use a plain JoinPoint. ProceedingJoinPoint is used as an argument of the methods which hints for before, after, after throwing and around. ProceedingJoinPoint has the methods like getKind, getTarget, proceed etc.

    12. Question 12. What Are The Five Advice Types Called?

      Answer :

      1. Before
      2. After
      3. AfterThrowing
      4. AfterReturning
      5. Around

    13. Question 13. What Are The Limitations Of Spring Aop?

      Answer :

      • Can only advise non-private methods
      • Can only apply aspects to Spring Beans
      • Limitations of weaving with proxies
      • When using proxies, suppose method a() calls method b() on the same class/interface
      • advice will never be executed for method b()

    14. Question 14. What Are The Supported Aspectj Pointcut Designators In Spring Aop?

      Answer :

      • Execution
      • This
      • Target
      • Args
      • @target
      • @args
      • @within
      • @annotation

    15. Question 15. How To Declare Aspect In Spring Aop?

      Answer :

      In XML.

      <bean class="com.doj.aop.LoggingAspect" id="loggingAspect">

      <!-- configure properties of aspect here -->


      In Java



      class LoggingAspect{




    16. Question 16. How To Declare A Pointcut In Spring Aop?

      Answer :

      Find the below code snippet.

      @Pointcut("execution(* save(..))")

      private void dataSave {}

    17. Question 17. What Do You Understand By Load-time Weaving (ltw) In Spring?

      Answer :

      Load-time weaving (LTW) or Run time weaving is a process of weaving AspectJ aspects into the classes of the application when the classes are being loaded in JVM.

    18. Question 18. What Is Aspect Oriented Programming (aop) In Spring?

      Answer :

      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.

    19. Question 19. Define Aop Terminologies In Spring?

      Answer :

      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.

    20. Question 20. Define The Types Of Advice In Spring Aop.

      Answer :

      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. 

    21. Question 21. How To Enable @aspectj Support?

      Answer :

      Include the below XML code in application XML


    22. Question 22. When To Use Spring Aop And When To Use Full Aspectj?

      Answer :

      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.

    23. Question 23. What Are The Required Libraries To Run Aspectj Ltw In Spring?

      Answer :

      1. spring-aop.jar
      2. aspectjrt.jar
      3. aspectjweaver.jar

    24. Question 24. What Is The Concept Of Aop? Which Problem Does It Solve?

      Answer :

      Aspect-Oriented Programming (AOP) is another way of thing to some areas of application i.e. cross cutting concern like security, logging and transaction. AOP is simple complement of OOP programming for different concerns. In OOP, the key unit of modularity is the class, whereas in AOP the unit of modularity is the aspect.

      Aspect-Oriented Programming (AOP) enables modularization of cross-cutting concerns to solve following problems.

      • To avoid tangling
      • To eliminate scattering.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Spring MVC Framework Tutorial