SpringBoot自定义监听器

匿名 (未验证) 提交于 2019-12-03 00:39:02

自定义一个类实现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(); 	} }

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!