Spring Aop Interview Questions & Answers

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

    Answer :

    Pointcut

    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

    Advice

    Code to be executed at each selected Join Point

    Aspect

    A module that encapsulates pointcuts and advice

    Weaving

    Technique by which aspects are combined with main code

    Introduction

    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. J2EE Interview Questions

  4. 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
  5. 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.

  6. J2EE Tutorial

  7. 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:

    @Configuration

    @EnableAspectJAutoProxy

    public class AppConfig {

    }

    Enabling @AspectJ Support with XML configuration

    To enable @AspectJ support with XML based configuration use the element:

  8. Java-Springs Interview Questions

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

    Answer :

    1. Logging
    2. Security
    3. Transaction
  10. Question 7. What Does @enableaspectjautoproxy Do?

    Answer :

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

    @Configuration

    @EnableAspectJAutoProxy

    public class AppConfig {

    }

  11. Java-Springs Tutorial
    Hibernate Interview Questions

  12. Question 8. What Is A Named Pointcut?

    Answer :

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

       

  13. 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.

  14. Core-Spring (based on Spring 3 . 2) Interview Questions

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

    Answer :

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

  16. Hibernate Tutorial

  17. 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.

  18. MVC Framework Interview Questions

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

    Answer :

    1. Before
    2. After
    3. AfterThrowing
    4. AfterReturning
    5. Around
  20. J2EE Interview Questions

  21. 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()
  22. MVC Framework Tutorial

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

    Answer :

    • Execution
    • This
    • Target
    • Args
    • @target
    • @args
    • @within
    • @annotation
  24. Question 15. How To Declare Aspect In Spring Aop?

    Answer :

    In XML.

    In Java

    @Aspect

    @Component

    class LoggingAspect{

    //advice

    //pointcut 

    }

  25. Framework7 Interview Questions

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

    Answer :

    Find the below code snippet.

    @Pointcut(“execution(* save(..))”)

    private void dataSave {}

  27. Framework7 Tutorial

  28. 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.

  29. Maven Interview Questions

  30. 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.

  31. Java-Springs Interview Questions

  32. 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.

  33. Maven Tutorial

  34. 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. 

  35. Java collections framework Interview Questions

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

    Answer :

    Include the below XML code in application XML

  37. 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.

  38. JUnit Tutorial

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

    Answer :

    1. spring-aop.jar
    2. aspectjrt.jar
    3. aspectjweaver.jar
  40. JUnit Interview Questions

  41. 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.
  42. Hibernate Interview Questions