Spring Application Services

Exercise: Hello Application (Configuration Classes)




  1. Configuration Classes
    • Remove the annotations from the service classes and the command line runner
    • Implement a configuration class ApplicationConfig that provides factory methods for the services
    • Create the command line runner in a factory method of the application class
  2. Profiles
    • Add the existing command line runner to the profile dev
    • Create another runner that asks the user for his name and age, and add it to the profile prod
    • Run the application using the spring.profiles.active command line option
  3. External Configuration
    • Write a configuration file application.properties that contains a property for the adult age
    • Inject the property value into the Hello service to decide which message to return
    • Use a command line option to override the property value
  4. Type-safe Configuration
    • Implement a configuration class TimesOfDay with properties for the times of day
    • Add the spring-boot-starter-validation starter and use annotations to validate the properties
    • Add the spring-boot-configuration-processor starter to generate a configuration metadata file
    • Inject an instance into the Greeting service to generate an appropriate daytime greeting

Solution