A Simple Example of Using Spring Aspect Oriented Programming to Log the Beginning and End of All Methods in All Classes in a Package
I have often seen, in development work, certain types of code fragments that get repeated many times throughout the code, which would seem a prime use case for Aspect Oriented Programming (AOP). I thought I would try creating an aspect to do debug logging in my Biking Weather Suitability Forecast application as follows: Do the following debug logging items for all methods in all classes in the biz.noip.johnwatne.bikingweather.service package. Log the start of a method's execution, including the name of the method and listing the parameters passed to it. For methods that return an Object or value, log the item returned. For void methods, indicate the end of the method's execution. Allow toggling the enabling of the aspect's code based on the value of a property in the application's properties file. This allows temporarily enabling the logging while testing new development, then disabling it, or, alternatively, having environment-specific properties files that woul...