spring bootのSpringApple事件の傍受


spring aplication listener
スプリングフレームワークでは、複数のイベントがありますが、これらの時間は別の運行時刻にリリースされ、モニターに通知されます。本論文ではSprigAplication Eventのイベントの傍受についてのみ紹介します。
イベントの種類
イベントType
リリース時間
Appliation Contect tInitialized Event
はい、 SpringApplicationが起動しています。 Apple Comptext もう準備しました。Application Contect Initializers。 呼び出しられます bean definitions ロードされる前に
Apple StartingEvent
一回の起動前にリリース
アプリエンタテインメントEvironment PreparedEvent
はい、 Evironment 準備ができたら、あります。 context これを使いに行きます Evironmentは context 作成前に送信
Apple PreparedEvent
会がある bean definitions 読み込み後、refresh 前にリリース
Apple StartEdent
context 更新後、任意のアプリケーションまたはコマンドラインが起動される前に起動します。
Application ReadyEvent
アプリケーションまたはコマンドラインが起動してからリリースされます。アプリケーションは要求されます。
Application FailedEvent
起動に異常が発生した場合、ステップが発生します。
どうやって監督しますか
モニターはorg.springframewark.com.tentxt.Appliation Listenerを使用する必要があるというインターフェースの例を示しており、その声明は以下の通りである。

@FunctionalInterface
public interface ApplicationListener<E extends ApplicationEvent> extends EventListener {
  /**
  * Handle an application event. * @param event the event to respond to
  */ 
 void onApplicationEvent(E event);
}
SprigAplication.addListeners(…)またはSpringAppliation Builler.listeners(…)を使用してモニターを追加する必要があります。META-INF/spring.factoresファイルに配置することもできます。org.springframe ebork.co ntect.Appliation Listener=comp.example.project.MyListener。
例:

public class StartingEventListener implements ApplicationListener<ApplicationStartingEvent> {
 @Override
 public void onApplicationEvent(ApplicationStartingEvent applicationStartingEvent) {
  System.out.println("called own starting listener");

  System.out.println(applicationStartingEvent.getClass());
 }
}


@SpringBootApplication
public class DemoApplication {
 public static void main(String[] args){
  SpringApplication application = new SpringApplication(DemoApplication.class);
  application.addListeners(new StartingEventListener());
  application.run(args);
 }
}
端末はjarパッケージを実行します。

$ java -jar build/libs/springlisteners-0.0.1-SNAPSHOT.jar
called own starting listener
class org.springframework.boot.context.event.ApplicationStartingEvent

 .  ____     _      __ _ _
 /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/ ___)| |_)| | | | | || (_| | ) ) ) )
 ' |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::    (v2.1.3.RELEASE)
以上が本文の全部です。皆さんの勉強に役に立つように、私たちを応援してください。