Spring AOP Flashcards

1
Q

What are cross cutting concerns?

A

Functionalities that are orthogonal to the business requirement and cut across multiple points of application are called cross cutting concerns. Some examples are like Authentication, Authorization, Logging, Metrics, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Give example of common cross cutting concerns

A

Logging, Security, Transaction management

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does AOP provide us?

A

Ability to decouple these cross cutting concerns from main business logic and make the code resuable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which are various AOP jargons?

A

1) Aspect
2) Advice
3) Pointcut
4) JoinPoint

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Aspect?

A

Cross cutting concerns can be modularized into special classes called aspects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Advice?

A

The piece of code that is invoked during program execution. Advice defines both when and what of aspect.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Joinpoint?

A

This represents a point in your application where you can plug in AOP aspect. In spring a join point is always a method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is pointcut?

A

Pointcuts define the when of aspect. It is an expression which defines filter. This is a set of one or more joinpoints where an advice should be executed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is weaving?

A

Weaving is the process of linking the aspets with other application types or objects to create an adviced object. There are two types of weaving.

1) Compile time weaving
2) Runtime weaving.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which expression types are supported when defining pointcut?

A

1) execution
2) args
3) within
4) this
5) target

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Define execution expression in pointcut

A

For matching method execution join points, this is primary pointcut designator what you will use

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Define args expression in pointcut

A

Limits matching to joinpoints where the arguments are instances of the given types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Define within expression in pointcut

A

Limits matching to join points within certain types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Define this expression in pointcut

A

Limits matching to joinpoints where the bean reference is an instance of the given type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Define target expression in joinpoint

A

Limits matching to joinpoints where the target object is an instance of the given type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Pointcut expression for any method named ‘setData’

A

@PointCut(“execution(* setData(..))”)

17
Q

Pointcut expression for execution of any method defined by the AccountService class

A

@Pointcut(“execution(* co.edureka.spring.service.AccountService.*(..)”)

18
Q

Pointcut expression for execution of any method within the controllers package or a sub-package

A

within(co.edureka.controllers..*)

19
Q

Pointcut expression for execution of any method which takes a single parameter and where the argument passed at runtime is Date

A

args(java.util.Date)

20
Q

Pointcut expression for execution of any method where the target object implements the TransactionService interface

A

target(co.edureka.service.TransactionService)

21
Q

How many ways can you do AOP

A

Spring XML based or AspectJ annotation driven aspects

22
Q

Advice types supported in spring

A

Before, After, AfterReturning, AfterThrowing, Around

23
Q

Which interface is used to implement Before advice

A

MethodBeforeAdvice interface and it has before method.

24
Q

Which interface is used to implement After returning advice

A

AfterReturningAdvice interface is used and it has method afterReturning

25
Q

How to configure advice in spring xml?

A

Need to declare bean in xml. And then configure ProxyFactoryBean. And in proxy bean need to set property “target” and “interceptorNames”

26
Q

Which interface is used to create Around advice?

A

MethodInterceptor interface is used. It has invokeMethod and provides MethodInvocation object on which proceed method can be called to execute actual method.

27
Q

Which interface is used to implement After throwing advice?

A

AfterThrowingAdvice interface is used. it has method afterThrowing

28
Q

AspectJ annotations?

A
@Aspect,
@Before,
@After,
@AfterReturning,
@AfterThrowing,
@Pointcut
29
Q

How to enable aspecj annotations in spring

A

aop:asjectj-autoproxy tag

30
Q

How to define common pointcut configuration that can be reused at multiple places like multiple advices?

A

In a common class declare a method and annotate it with @Pointcut annotation and provide pointcut there. Then wherever you want to use the pointcut provide Fully qualified classname.methodname() in @Before, @After etc annotations.

31
Q

Which interface is used to implement After returning advice

A

AfterReturningAdvice interface is used and it has method afterReturning

32
Q

How to configure advice in spring xml?

A

Need to declare bean in xml. And then configure ProxyFactoryBean. And in proxy bean need to set property “target” and “interceptorNames”

33
Q

Which interface is used to create Around advice?

A

MethodInterceptor interface is used. It has invokeMethod and provides MethodInvocation object on which proceed method can be called to execute actual method.

34
Q

Which interface is used to implement After throwing advice?

A

AfterThrowingAdvice interface is used. it has method afterThrowing

35
Q

AspectJ annotations?

A
@Aspect,
@Before,
@After,
@AfterReturning,
@AfterThrowing,
@Pointcut
36
Q

How to enable aspecj annotations in spring

A

aop:asjectj-autoproxy tag

37
Q

How to define common pointcut configuration that can be reused at multiple places like multiple advices?

A

In a common class declare a method and annotate it with @Pointcut annotation and provide pointcut there. Then wherever you want to use the pointcut provide Fully qualified classname.methodname() in @Before, @After etc annotations.