public class WebContextListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContextEvent.getServletContext());
ISrInforService srInforService = applicationContext.getBean(ISrInforService.class);
// ISrInforService srInforService = (ISrInforService) applicationContext.getBean("srInforService");
srInforService.countAllSrInforsScore();
}
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
}
}
ISrInforService srInforService = applicationContext.getBean(ISrInforService.class);
或
ISrInforService srInforService = (ISrInforService) applicationContext.getBean("srInforService");
都可以。
然后配置web.xml
:
<!-- Spring监听配置,Web容器启动自动装配ApplicationContext的配置信息-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
参考:
最新评论
本来在正常下载,突然就不能下载,并出现报错:a socket operation was attempted to an unreachable network。请问是什么原因呢
试了,还是不行,能不能更新一下
试了,确实不行,能不能更新一下
也推荐一下我自己写的 https://twitdown.com