提供了两个接口,ApplicationRunner 和 CommandLineRunner ,实现重写run方法即可
BootApplicationRunner.java
package com.example.sdtest.runner;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class BootApplicationRunner implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
log.info("this is ApplicationRunner");
}
}
BootCommandLineRunner.java
package com.example.sdtest.runner;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class BootCommandLineRunner implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
log.info("this is CommandLineRunner");
}
}