spring读取配置文件的形式

spring读取配置文件的方式

一、解析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);