不多说,直接上代码
/**
* 项目启动成功的运行的代码
* @author xwq
* @create 2019-10-24 14:51
**/
@Component
public class ApplicationRunnerImpl implements ApplicationRunner{
@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println("--------启动成功-------");
String[] sourceArgs = args.getSourceArgs();
for (String arg : sourceArgs) {
System.out.print(arg + " ");
}
System.out.println();
}
}
或者实现CommandLineRunner接口
@Component
public class CommandLineRunnerImpl implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
System.out.println("通过实现CommandLineRunner接口");
}
}
项目中可以同时使用这俩种方法。