In the spring the actual development boot project, we sometimes need to load some data item or service to start in advance to complete certain actions. To solve this problem, Spring boot provides us with a method: to achieve this demand by implementing the interface CommandLineRunner.
Implementation: only one class without the need of additional configuration.
Implementation steps:
1. Create a class that implements the interface CommandLineRunner of MyStartupRunnerTest
- package com.energy;
- import org.springframework.boot.CommandLineRunner;
- import org.springframework.core.annotation.Order;
- import org.springframework.stereotype.Component;
- /**
- * Created by CavanLiu on 2017/2/28 0028.
- */
- @Component
- @Order(value=1)
- public class MyStartupRunnerTest implements CommandLineRunner
- {
- @Override
- public void run(String... args) throws Exception
- {
- System.out.println(">>>>This is MyStartupRunnerTest Order=1. Only testing CommandLineRunner...<<<<");
- }
- }