1、spring.factories
# SpringApplicationRunListener
org.springframework.boot.SpringApplicationRunListener=\
com.imooc.springapplication.run.HelloWorldSpringApplicationRunListener
2、HelloWorldSpringApplicationRunLIistener
package com.imooc.springapplication.run;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
public class HelloWorldSpringApplicationRunListener implements SpringApplicationRunListener {
//构造器
public HelloWorldSpringApplicationRunListener(SpringApplication springApplication, String[] args){
}
@Override
public void starting(){
System.out.println("HelloWorld start run listener");
}
@Override
public void environmentPrepared(ConfigurableEnvironment environment){
}
@Override
public void contextPrepared(ConfigurableApplicationContext context){
}
@Override
public void contextLoaded(ConfigurableApplicationContext context){
}
@Override
public void started(ConfigurableApplicationContext context){
}
@Override
public void running(ConfigurableApplicationContext context){
}
@Override
public void failed(ConfigurableApplicationContext context, Throwable exception){
}
}
3、运行结果
HelloWorld start run listener
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.0.BUILD-SNAPSHOT)