For BE/B.Tech/BCA/MCA/ME/M.Tech Major/Minor Project for CS/IT branch at minimum price Text Message @ 9424820157

Spring AOP Interview Questions

Spring AOP Interview Questions



Explain Spring AOP.

Aspect-oriented programming (AOP) refers to a programming technique that allows programmers to modularize crosscutting concerns or behavior that cuts across the typical divisions of responsibility, such as logging and transaction management.

 

What is Aspect in Spring AOP?

The core construct of AOP is the aspect that encapsulates behaviors affecting multiple classes into reusable modules.

 

It is a module that has a set of APIs providing cross-cutting requirements. For example, a logging module would be called the AOP aspect for logging. An application can have any number of aspects depending on the requirement. In spring AOP, aspects are implemented using regular classes annotated with @Aspect annotation (@AspectJ style).

 

Explain the differences between concern and cross-cutting concern in spring AoP.

The concern is behavior that we want to have in a particular module of an application. A concern may be defined as functionality we want to implement.

 

The cross-cutting concern is a concern that is applicable throughout the application and it affects the entire application. For example, logging, security, and data transfer are applicable for every module of an application hence they are cross-cutting concerns.

 

Explain Joinpoint in spring AOP.

The Joinpoint represents a point in an application where we can plug in an AOP aspect. It is the actual place in the application where an action will be taken using the Spring AOP framework.

 

What is Advice in Spring AOP?

The advice is the actual action that will be taken either before or after the method execution. This is the actual piece of code that is invoked during the program execution by the Spring AOP framework.

Spring aspects can work with five different advices.

before: Run advice before the method execution.

after: Run advice after the method execution regardless of its outcome.

after-returning: Run advice after the method execution only if the method completes successfully.

after-throwing: Run advice after the method execution only if the method exits by throwing an exception.

around: Run advice before and after the advised method is invoked.

What is Pointcut in Spring AOP?

The pointcut is a set of one or more joinpoints where advice should be executed. You can specify pointcuts using expressions or patterns.

 

What is Introduction in Spring AOP?

An Introduction allows us to add new methods or attributes to existing classes.

 

 

What is 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 also referred to as the advised object.

 

What is a Proxy in Spring AOP?

A proxy is an object that is created after applying advice to a target object. when you think of client objects the target object and the proxy object are the same.

 

What are the different types of AutoProxying in Spring AOP?

BeanNameAutoProxyCreator,

DefaultAdvisorAutoProxyCreator,

and Metadata autoproxying.

What is weaving in Spring AOP? What are the different points where weaving can be applied?

Weaving is the process of linking aspects with other application types or objects to create an advised object. Weaving can be done at compile-time, at load time, or at runtime.

 

Explain XML schema-based aspect implementation in spring AOP.

In this implementation case, aspects are implemented using regular classes along with XML-based configuration.

 

Explain annotation-based (@AspectJ based) aspect implementation in spring AOP.

This implementation case (@AspectJ based implementation) refers to a style of declaring aspects as regular Java classes annotated with Java 5 annotations.

 

What are the types of Advice in Spring AOP?

There are 5 types of Advice.

 

Before Advice. Advice that is executed prior to a joinpoint.

After returning advice. Advice that is executed after the normal completion of a joinpoint.

After throwing advice. Advice that is executed only if a method exits abnormally by throwing an exception.

Finally advice. Advice that is executed irrespective of how a joinpoint exit.

Around advice. Advice that borders a joinpoint, for example, a method invocation. The advice can execute before and after the invocation of the method.


What is AOP Alliance?

AOP Alliance is an open-source project which is aimed at promoting the adoption of AOP. The AOP alliance goal is to define a common set of components and interfaces so as to improve interoperability among different AOP implementations.

 

What do the proxy-target-class attributes do in Spring AOP?

To force the use of CGLIB proxies set the value of the proxy-target-class attribute of the element to true.

 

<aop:config proxy-target-class="true">

    <!-- other beans defined here... -->

</aop:config>

How spring AOP works?

Spring AOP is proxy-based. Spring uses either JDK proxy preferred whenever the proxied target implements at least one interface or CGLIB proxy when the target object does not implement any interfaces, to create the proxy for a given target bean.

 Spring AOP performs run-time weaving. You can however, set up Spring to do load-time weaving through AspectJ.


Which design pattern is used in Spring AOP?

AOP is mainly based on Proxy design pattern. It also uses remoting, Singleton, template method, and decorator design pattern.

 

Difference between Spring AOP and AspectJ.

Spring AOP does runtime weaving by default while Aspect is compile-time weaving.

Spring AOP doesn't work with final class or final/static methods because it may not able to create proxy by subclassing. AspectJ works with final class as it does compile-time weaving and not depend on proxy pattern.

 

Mention a few AOP implementations.

Spring AOP,

JBoss AOP,

Apache AspectJ.

 

No comments:

Post a Comment



Please go through below tutorials:


Mule 4 Tutorials

DEPLOY TO CLOUDHUB C4E CLIENT ID ENFORCEMENT CUSTOM POLICY RABBIT MQ INTEGRATION
XML TO JSON WEBSERVICE CONSUMER VM CONNECTOR VALIDATION UNTIL SUCCESSFUL
SUB FLOW SET & REMOVE VARIABLE TRANSACTION ID SCATTER GATHER ROUND ROBIN
CONSUME REST WEBSERVICE CRUD OPERATIONS PARSE TEMPLATE OBJECT TO JSON LOAD STATIC RESOURCE
JSON TO XML INVOKE IDEMPOTENT FILTER FOR EACH FLAT TO JSON
FIXWIDTH TO JSON FIRST SUCCESSFUL FILE OPERATIONS EXECUTE ERROR HANDLING
EMAIL FUNCTIONALITY DYNAMIC EVALUATE CUSTOM BUSINESS EVENT CSV TO JSON COPYBOOK TO JSON
CHOICE ASYNC

Widely used Connectors in Mule 3

CMIS JETTY VM CONNECTOR SALESFORCE POP3
JMS TCP/IP WEBSERVICE CONSUMER QUARTZ MONGO DB
FILE CONNECTOR DATABASE CONNECTOR


Widely used Scopes in Mule 3

SUB FLOW REQUEST REPLY PROCESSOR CHAIN FOR EACH CACHE
ASYNC TCP/IP COMPOSITE SOURCE POLL UNTIL SUCCESSFUL
TRANSACTIONAL FLOW

Widely used Components in Mule 3

EXPRESSION CXF SCRIPT RUBY PYTHON
JAVASCRIPT JAVA INVOKE CUSTOM BUSINESS EVENT GROOVY
ECHO LOGGER


Widely used Transformers in Mule 3

MONGO DB XSLT TRANSFORMER REFERENCE SCRIPT RUBY
PYTHON MESSAGE PROPERTIES JAVA TRANSFORMER GZIP COMPRESS/UNCOMPRESS GROOVY
EXPRESSION DOM TO XML STRING VALIDATION COMBINE COLLECTIONS BYTE ARRAY TO STRING
ATTACHMENT TRANSFORMER FILE TO STRING XML TO DOM APPEND STRING JAVASCRIPT
JSON TO JAVA COPYBOOK TO JSON MAP TO JSON JSON TO XML FLATFILE TO JSON
FIXWIDTH TO JSON CSV TO JSON


Widely used Filters in Mule 3

WILDCARD SCHEMA VALIDATION REGEX PAYLOAD OR
NOT MESSAGE PROPERTY MESSAGE IDEMPOTENT FILTER REFERNCE
EXPRESSION EXCEPTION CUSTOM AND


Exception Strategy in Mule 3

REFERENCE EXCEPTION STRATEGY CUSTOM EXCEPTION STRATEGY CHOICE EXCEPTION STRATEGY CATCH EXCEPTION STRATEGY GLOBAL EXCEPTION STRATEGY


Flow Control in Mule 3

CHOICE COLLECTION AGGREGATOR COLLECTION SPLITTER CUSTOM AGGREGATOR FIRST SUCCESSFUL
MESSAGE CHUNK AGGREGATOR MESSAGE CHUNK SPLITTER RESEQUENCER ROUND ROBIN SOAP ROUTER