I have spring boot project, that is working very fine. But when i add the spring AOP it causes nullpointer when i used the @Autowired variable.
Here is my code for the AOP .
@Autowired
private Service service;
private final org.apache.commons.logging.Log log = LogFactory.getLog(this.getClass());
@Around("execution(* com.kpi.ninja..*.*(..))")
public Object logTimeMethod(ProceedingJoinPoint joinPoint) throws Throwable {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
System.out.println("Entering in Method : " + joinPoint.getSignature().getName());
System.out.println("Class Name : " + joinPoint.getSignature().getDeclaringTypeName());
System.out.println("Target class : " + joinPoint.getTarget().getClass().getName());
Object retVal = joinPoint.proceed();
stopWatch.stop();
StringBuffer logMessage = new StringBuffer();
logMessage.append(joinPoint.getTarget().getClass().getName());
logMessage.append(".");
logMessage.append(joinPoint.getSignature().getName());
logMessage.append("(");
// append args
Object[] args = joinPoint.getArgs();
for (int i = 0; i < args.length; i++) {
logMessage.append(args[i]).append(",");
}
if (args.length > 0) {
logMessage.deleteCharAt(logMessage.length() - 1);
}
logMessage.append(")");
logMessage.append(" execution time: ");
logMessage.append(stopWatch.getTotalTimeMillis());
logMessage.append(" ms");
log.info(logMessage.toString());
return retVal;
}