I have written my pointcut and custom around advise, which will execute one Dao method.
Pointcut
@Pointcut("execution(* com.dao.*.get*(..))")
public void creditPointcut(){
}
Around Advice
@Around("creditPointcut()")
public void around(ProceedingJoinPoint point) throws Throwable{
LOGGER.info("Method name: "+point.getSignature().getName()+" started");
point.proceed();
LOGGER.info("Method name: "+point.getSignature().getName()+" ended");
}
Target - Dao Method
public Account getAccountDetails(int accntNo) {
Session session = sessionFactory.getCurrentSession();
Query query = session.createQuery("from Account where accountNo=:acctNo");
query.setInteger("acctNo", accntNo);
Account account = (Account)query.list().get(0);
return account;
}
But, this advice returns null account in my service.
Service layer method
@Override
@Transactional(isolation=Isolation.READ_COMMITTED )
public Account getAccountDetails(int accntNo) {
Account account = accountDao.getAccountDetails(accntNo);
return account;
}
Please help me why i am getting null account in my service, after executing the around advice in Dao.
After advice is used in Aspect-Oriented Programming to achieve the cross-cutting. It is an advice type which ensures that an advice runs after the method execution. We use @After annotation to implement the after advice.
Run advice after the method execution, regardless of its outcome. Run advice after the method execution, only if the method completes successfully. Run advice after the method execution, only if the method exits by throwing an exception. Run advice before and after the advised method is invoked.
Around Advice is the strongest advice among all the advice since it runs “around” a matched method execution i.e. before and after the advised method. It can choose whether to proceed to the join point or to bypass join point by returning its own return value or throwing an exception.
That's because you are not returning anything from the advice:
@Around("creditPointcut()")
public Object around(ProceedingJoinPoint point) throws Throwable{
LOGGER.info("Method name: "+point.getSignature().getName()+" started");
Object ret = point.proceed();
LOGGER.info("Method name: "+point.getSignature().getName()+" ended");
return ret;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With