title: How to run CommandLineRunner in spring boot
body: <p>I'm working on an application using spring.
  I expect its run to be called when the app starts.
  But it doesn't seem work even if the code and the setting is both ok.
  Here's the code.</p>
  <pre><code>package mrs;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  @SpringBootApplication
  public class SpringJpa2Application {
  
      public static void main(String[] args) {
          SpringApplication.run(SpringJpa2Application.class, args);
      }
  
  }
  </code></pre>
  <pre><code>package config;
  
  import org.springframework.boot.CommandLineRunner;
  import org.springframework.stereotype.Component;
  
  import mrs.model.Comment;
  import mrs.repository.CommentRepository;
  
  import lombok.RequiredArgsConstructor;
  
  @RequiredArgsConstructor
  @Component
  public class DataLoader implements CommandLineRunner{
      private final CommentRepository repository;
      
      @Override
      public void run(String... args) throws Exception{
          System.out.println(&quot;start&quot;);
  
          //doSomething
  
          System.out.println(&quot;done&quot;);
      }
  }
  
  </code></pre>