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>
参考:
最新评论
我的是ipv4网络,如何使用直播源啊!
我今天试了,不想啊,我的是新疆昌吉移动的网络。
收不到验证码电报
现在充值29起了