spring aop annotation

Jackie
Nov 13, 2020

--

when annotating an advice method with the pointcut, spring throws an error

error Type referred to is not an annotation type: LogCommands

Turns out spring is picking up the annotation name and using it for reflection and then load the interface for AOP stuff.

So the solution is to mark the type as complete full interface name, (unless its within same package)

for example, instead of

@Before("@annotation(LogCommands)")

public void logCommands(JoinPoint joinPoint) throws Throwable {

String command = joinPoint.getSignature().getName();

String input = Arrays.stream(joinPoint.getArgs()).toString();

.....

}

a FQN make it work

@Before("@annotation(com.abc.svc.annotation.LogCommands)")
public void logCommands(JoinPoint joinPoint) throws Throwable {
String command = joinPoint.getSignature().getName();
String input = Arrays.stream(joinPoint.getArgs()).toString();
.....
}

--

--

No responses yet