Springboot在服务启动时运行加载的功能

1、实现ApplicationRunner

@Component
@Order(value = 1)//执行顺序
public class ConsumerService implements ApplicationRunner{
	@Override
	public void run(ApplicationArguments arg0) throws Exception {
		System.out.println("启动执行...");
	}
}

2、实现CommandLineRunner


@Component
public class ConsumerService implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {
        System.out.println("启动执行...");
    }
}

 

你可能感兴趣的:(Springboot在服务启动时运行加载的功能)