SpringBoot入门之事件监听
spring boot在启动过程中增加事件监听机制,为用户功能拓展提供极大的便利,sptingboot支持的事件类型有以下五种: ApplicationStartingEvent ApplicationFailedEvent ApplicationPreparedEvent ApplicationReadyEvent ApplicationEnvironmentPreparedEvent 实现监听步骤 1.监听类实现ApplicationListener接口 2.将监听类添加到SpringApplication实例中 ApplicationStartingEvent ApplicationStartingEvent:springboot启动开始的时候执行的事件,在该事件中可以获取到 SpringApplication 对象,可做一些执行前的设置。 package com.ysl.listener; import org.springframework.boot.Banner; import org.springframework.boot.SpringApplication; import org.springframework.boot.context.event.ApplicationStartingEvent; import org