Spring Application Services

Exercise: Hello Application (Basic Components)




  1. Command Line Runner
    • Implement a Spring Boot application with a command line runner HelloRunner as component
    • In the run method, print a hello message to the console
  2. Service Components
    • Implement a service HelloService with a method sayHello(Sting name, int age) that returns a casual or formal message depending on the age of the user
    • Implement a service GreetingService with a getGreeting() method that returns a greeting depending on the daytime
  3. Dependency Injection
    • Inject the Greeting service into the Hello service and use it to create the formal hello message
    • Inject the Hello service into the command line runner and invoke its method
  4. Lifecycle Callbacks
    • Implement the lifecycle callbacks PostConstruct and PreDestroy to observe the construction and destruction of the service instances

Solution