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>
参考:
最新评论
下载不了了
怎么联系你呢?
怎么用啊?怎么怎么联系你
第一个国内和国际频道不能用,用我的电视显示链接失效。而且家里网络支持ipv6