一、解析classpath的应用上下文环境:
ApplicationContext context = new ClassPathXmlApplicationContext("application-timer.xml");
PropertiesBean propertiesBean = (PropertiesBean) context.getBean("propertiesBean");
二、通过Spring提供的工具类获取ApplicationContext对象,可以从web-inf目录下读取xml文件:
ServletContext servletContext = request.getSession().getServletContext();
ApplicationContext factory = WebApplicationContextUtils.getWebApplicationContext(servletContext);
本文介绍了如何使用Spring框架从不同的应用上下文中加载配置文件。包括使用ClassPathXmlApplicationContext从classpath中加载XML配置文件,以及利用WebApplicationContextUtils工具类从web-inf目录下获取配置。

被折叠的 条评论
为什么被折叠?



