有两种方式
1.实现 ApplicationRunnerImpl
eg:
package com.example.demo.configure;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
@Component
public class ApplicationRunnerImpl implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println("application start...");
}
}
2.实现 CommandLineRunnerImpl
eg:
package com.example.demo.configure;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
public class CommandLineRunnerImpl implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
System.out.println("application start...");
}
}
若是有多个实现类,则需要加上@Order注解,按照其中的value值从小到大执行。