使用方法详见:https://blog.youkuaiyun.com/catoop/article/details/50501710
探索一下该接口的实现,在该Application中的执行顺序:
import org.springframework.stereotype.Controller;
/**
* @author
* @date 2019/5/10 14:17
*/
@Controller
public class RunnerOrderTestController {
static{
System.out.println("Controller的静态代码块");
}
{
System.out.println("Controller的动态代码块");
}
}
import com.example.demo.springCach.User;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author
* @date 2019/5/10 14:16
*/
@Configuration
public class RunnerOrderTestConfig {
@Bean
public User testOrder(){
System.out.println("我是Configuration中的Bean");
return null;
}
}
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
/**
* @author
* @date 2019/5/10 14:14
*/
@Component
public class RunnerOrderTestRunner implements CommandLineRunner{
@Override
public void run(String... strings) throws Exception {
System.out.println("我是一个CommandLineRunner实例");
}
}
结果是 CommandLineRunner实例会在Boot项目启动完成之后执行。