Let’s assume we have to pass some parameters to the aspect that intercept method invocations.
It may be for example the level of logging (DEBUG, INFO, WARNING and so on), format (plain text, JSON, XML), name of the web service.
First we need to add a parameter Service service to our annotation
Doing that we don’t need to have separate annotations like @LogBookService, @LogCustomerService and @LogInventoryService for each service anymore. We just pass a service as a parameter.
Accessing annotation parameters
Now we can access that parameter from an aspect just like this
Logger aspect
Finally in our ServiceLogger aspect we have one @Around for all services
Aspect weaving
The last thing we need to setup is pom.xml to properly weave our aspects.