I have a Spring application, and Im trying to understand how long all the PostConruct takes.
but this method isn't getting called, what am I missing ?
@Component
@Aspect
@Order(1)
public class InspectorTime {
@Around("@within(javax.annotation.PostConstruct)")
public void beforePostConstruct(ProceedingJoinPoint joinPoint) throws Throwable {
LOG.info("Before PostContract:{}", joinPoint.getSignature().getDeclaringType().toString());
StopWatch stopWatch = new StopWatch();
stopWatch.start();
joinPoint.proceed(joinPoint.getArgs());
stopWatch.stop();
LOG.info("After PostContract:{}", joinPoint.getSignature().getDeclaringType().toString() + ", total time" + stopWatch.toString());
}
}
I have followed, these solutions @Before @PostConstruct Spring AOP ineterception but they also estimate the "Autowire" timing. I need to estimate the postContruct only.
I also tried this Code
@Around("@annotation(javax.annotation.PostConstruct)")
public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
Object proceed = joinPoint.proceed();
long executionTime = System.currentTimeMillis() - start;
logger.info("{}.{} executed in {} ms", joinPoint.getSignature().getDeclaringTypeName(),
joinPoint.getSignature().getName(), executionTime);
return proceed;
}
But its making my other beans to failed to instantiate:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.core.RedisTemplate]: Factory method 'redisTemplate' threw exception; nested exception is java.lang.NullPointerException