Spring Custom Annotation

Annotation Interface

Sivaram Rasathurai
1 min readNov 23, 2021

Spring AOP is very simple implementation of AOP concepts. It's an idea fit

Aspect

The cross-cutting thing you are going to do with AOP. Aspect is the concern that we are trying to implement generically.

Pointcut

The expression determines which calls are intercepted.

Advice

What is to be done in Aspect / the point cut met?

Joinpoint

Weaving

@Retention(RetentionPolicy.RUNTIME)
@target({ElementType.TYPE, ElementType.Method})
@interface CustomAnno{
int var0() default 0;
String var1() default "custom";
}
  1. var0, var1 are variables /attributes / elements.( primitive data types and the array can be used)
  2. @retention → Availability of the annotation.
  3. @target → The target Java elements where the annotation can be added(Method, Package, parameter and etc)

Logic Class

@Aspect
@Component
public CustomAnnoLogicImplementation{
@Around("@annotation(com.rcvaram.annotation.CustomAnno)")
public Object implementLogic(ProceedingJointPoint point){
//Logic1 before executing the point
Object obj = point.proceed();
// Logic2 After executing the point
retun obj;
}
}

Implementation

public class Test{

@CustomAnno(var0=5, var1="testing")
public void test(){
//Some Logic
}
}

when this test method is called the logic1 will be called before the method and after executing the method the logic 2 will be called.

CustomTimeTracker Annotation

--

--