Using the command-line runners
With our basic application skeleton ready, let's add some meat to the bones by making our application do something.
Let's start by first creating a class named StartupRunner
. This will implement the CommandLineRunner
interface, which basically provides just one method: public void run(String... args)
--that will get called by Spring Boot only once after the application has started.
How to do it...
- Create the file named
StartupRunner.java
under thesrc/main/java/com/example/bookpub/
directory from the root of our project with the following content:
package com.example.bookpub; import com.example.bookpub.repository.BookRepository; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.scheduling.annotation.Scheduled; public class...