在web.xml中
<!-- 指定spring核心配置文件路径 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <!-- 配置监听器,当工程启动时,创建ioc容器,存放在ServletContext中 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
2.servlet获取IOC
//从ServletContext中获取唯一的IOC容器 ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext()); //从IOC容器中获取AccountService AccountService accountService = (AccountService) ac.getBean("accountService");
核心监听器(启动工程时创建IOC)
最新推荐文章于 2025-01-02 22:48:29 发布
