I am using Spring MVC for web applications and for Audit logging I am using AOP and it works when I log the changes using log4j. I want to dump these changes to database and for this I am using Autowired DAO inside my Aspect bean as below.
Can somebody let me know why it fails? I am really not sure about the sequence of things when aspects come in to play at runtime.
Code:@Aspect public class LoggingInterceptor { Log log = LogFactory.getLog(LoggingInterceptor.class); @Autowired private AuditData auditData; @Around("@annotation(com.xx.yy.util.audit.Auditable)") public Object profile(ProceedingJoinPoint pjp) throws Throwable { final String currentUser = SecurityContextHolder.getContext().getAuthentication().getName(); try { Object resultValue = pjp.proceed(); if (log.isErrorEnabled()) { logInfo(currentUser, pjp); System.out.println("dao: " + auditData); // am getting this as null // logAudit(currentUser, pjp); //dump changes to db } return resultValue; } finally { // sw.stop(); } } }


Reply With Quote
