Adding After advice

Let's add After advice for all the methods from BookDAO:

  1. Add an afterAdvise()method in MyLoggingAspect for after advice, as shown in the following piece of code:
public void afterAdvise(JoinPoint joinPoint) { 
  logger.info("executed successfully :- 
  "+joinPoint.getSignature()); 
} 
  1. Configure the pointcut expression to target all the methods inside the BookDAO class and After advice in the connection_new.xml file inside the myLogger aspect, as shown in the following lines of code:
<aop:pointcut id="pointcut2" 
  expression="execution(*  
    com.packt.ch03.dao.BookDAO.*(..))"/> 
<aop:afterpointcut-ref="pointcut2" method="afterAdvise"/> 
  1. Execute MainBookDAO_operations.java to get the following output:
999  [main] INFO  com.packt.ch04.aspects.MyLoggingAspect  - method will be invoked :-int com.packt.ch03.dao.BookDAO.addBook(Book) 
1360 [main] INFO  com.packt.ch04.aspects.MyLoggingAspect  - executed successfully :-int com.packt.ch03.dao.BookDAO.addBook(Book) 
book inserted successfully 
1418 [main] INFO  com.packt.ch04.aspects.MyLoggingAspect  - executed successfully :-int com.packt.ch03.dao.BookDAO.updateBook(long,int) 
book updated successfully 
1466 [main] INFO  com.packt.ch04.aspects.MyLoggingAspect  - executed successfully :-boolean com.packt.ch03.dao.BookDAO.deleteBook(long) 
book deleted successfully 

The statements make it clear that the advice got invoked after all the methods.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.161.77