在监听器启动之前得先加载spring bean,所以注解在监听器里是不能用的。
可以通过下面的方法获取需要的bean
public void contextInitialized(ServletContextEvent event) {
System.out.println("初始化 application");
ServletContext application = event.getServletContext();
WebApplicationContext appctx = WebApplicationContextUtils.getWebApplicationContext(application);
RoomService roomService = appctx.getBean(RoomService.class);
//等等
}
原文链接:https://blog.csdn.net/w605283073/article/details/50719650
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。
还没有人抢沙发呢~