Posts

Showing posts with the label Spring

Making REST Calls Retryable in Biking Weather Suitability Forecast Application

One frustration I had noticed with my Biking Weather Suitability Forecast Application was that I found it often would not show results until I reloaded the page, and a look at the application logs showed that the REST calls to one of the APIs called had failed or timed out. After doing some research into using Spring's Retryable options for methods, I decided to make the DailyReportCollectionService method getCurrentDailyReports() retryable, so that it would be attempted a second time after a one second pause if the first try didn't succeed in returning complete data, with a third and final attempt made as the " Recover " option. First, I added the following two required dependencies to the dependencies section of the application's pom.xml file. <dependency> <groupId>org.springframework.retry</groupId> <artifactId>spring-retry</artifactId> </dependency> <dependency...

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...