Posts

Showing posts from December, 2022

Aspect Oriented Programming to trace the requests and responses to a REST method in Spring Boot.

Image
  Aspect Oriented Programming ( AOP ) is one of the key feature of Spring framework. AOP is similar to OOPS concept where it breaks code into multiple reusable modules. AOP provides the capability to dynamically add module at runtime. This is like injecting complete module(logging, cahcing, etc ) in Spring framework dynamically. Logging, caching, security, monitoring, etc. are some of the examples cross cutting concern from AOP. At any point of time there modules can be added dynamically. Spring AOP has interceptors which can intercept application and its methods. This is to perform some extra action at the time of property initiation, method initialization or destroy. Let's try it to create a custom annotation to trace the requests and responses to a REST method in Spring Boot At first you we need to use spring-boot-starter-web and spring-boot-starter-aop dependencies to make it work. STEP1 : An interface with the annotation name @Traceable Now , in whichever method you add the...