spring的模块化配置文件加载

基于servlet3.0引入的模块化开发,web-fragment.xml文件让web应用开发变得更方便,模块化,通过在web-fragment.xml中添加模块对应的listener,filter,servlet来实现相应的逻辑,其中通过监听器引入模块私有的spring文件 也是常有的需求,见代码;

public class PlatformListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        
        ServletContext servletContext = sce.getServletContext();

        //加载私有配置文件
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[]{"classpath:applicationContext.xml"}, ApplicationContextUtils.getApplicationContext());
        ApplicationContextTest act = applicationContext.getBean(ApplicationContextTest.class);
        act.say();
        WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
    }
}


你可能感兴趣的:(spring,mvc)