|
Created by Jerry Reeves Jr
over 2 years ago
|
|
Question | Answer |
Is there difference between Object Oriented Programming (OOP) and Aspect-Oriented Programming (AOP)? | Object Oriented Programming (OOP) and Aspect-Oriented Programming (AOP) are not mutually exclusive. AOP can be good addition to OOP. OOP is mainly used to model business logic whereas AOP helps to organize non-functional aspects (called cross cutting concerns) like Auditing, Logging, Transaction Management, Security etc. AOP helps to build methods without clogging up the business code with the cross-cutting concerns. |
Why we need to use AspectJ in Spring application? | Spring provides simple and powerful ways of writing custom aspects (a modularization of a concern that cuts across multiple classes) by using @AspectJ annotation style. @AspectJ refers to a style of declaring aspects as regular Java classes annotated with annotations. The @AspectJ style was introduced by the AspectJ project as part of the AspectJ 5 release. Spring interprets the same annotations as AspectJ 5, using a library supplied by AspectJ for pointcut parsing and matching. Spring seamlessly integrates Spring AOP and IoC with AspectJ, to enable all uses of AOP within a consistent Spring-based application architecture. The @AspectJ support can be enabled with XML- or Java-style configuration. In either case, we also need to ensure that AspectJ’s aspectjweaver.jar library is on the class path of application (version 1.8 or later). This library is available in the lib directory of an AspectJ distribution or from the Maven Central repository. |
You must capture all exceptions caused in repository, service & controller layer using Spring AOP, how you can do it? | Exception being one of the cross-cutting concern in Spring application which can be handled using Spring AOP. Ensure the AspectJ dependencies are added in pom.xml file. Define central logging class named LoggingAspect.java we have defined pointcut expression for DAO, Service & Controller layer. The .. notation means "any package or subpackage", whereas * at the end of the expression after .. means "any method in any class". |
You have to measure performance (or time taken by method execution), how can you achieve it with AOP? | Apart from standard cross cutting concerns like Auditing, Logging, Transaction Management, Security etc. there are occasions where we want to deal with custom cross cutting concerns. Measuring performance of the method execution can be one of such example of cross cutting concerns. Ensure the AspectJ dependencies are added in pom.xml file. Define central logging class named ExecutionTimeAspect.java we have defined pointcut expression to measure performance of public String com.revature.service.RefundService.process(Long) method. |
Why we use pointcut expression in Spring application. | Pointcut is an expression language of spring AOP which is basically used to match the target methods to apply the advice. |
Why do we use @EnableAspectJAutoProxy? | Enables support for handling components marked with AspectJ's @Aspect annotation. This annotation is usually defined on class marked with @Configuration. |
There are no comments, be the first and leave one below:
Want to create your own Flashcards for free with GoConqr? Learn more.