SpringBoot自定义监听器

自定义一个类实现ApplicationListener即可,具体是监听什么事件,将事件填入泛型中< >

然后实现接口的方法即可

@Component
public class InitAdminListener implements ApplicationListener<ContextRefreshedEvent> {
	@Autowired
	private ILoginInfoService loginInfoService;
	@Autowired
	private ISystemAccountService systemAccountService;

	//所有bean加载完成之后要做的逻辑
	public void onApplicationEvent(ContextRefreshedEvent event) {

		loginInfoService.initAdmit();
		//初始化系统账号
		systemAccountService.initSystemAccount();
	}
}

猜你喜欢

转载自blog.csdn.net/hangbingbihai/article/details/80889689