1.启动类继承CommandLineRunner接口
2.如果预先加载多个用@Order(value=1) value=加载等级 等级数越小优先级越大
例
package com.example.demo; import com.example.demo.controller.NettyClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
//实现CommandLineRunner @SpringBootApplication public class DemoApplication implements CommandLineRunner { private static final Logger log = LoggerFactory.getLogger(DemoApplication.class); public static void main(String[] args) { SpringApplication app = new SpringApplication(DemoApplication.class); app.run(args); } @Override public void run(String... args) throws Exception { } }