美文网首页
servlet3.0 contextLoadListener

servlet3.0 contextLoadListener

作者: lovePython | 来源:发表于2015-08-18 10:59 被阅读223次

ContextLoadListener作用:

它会默认查找位于:WEB-INF/下的是否有一个文件名称为:applicationContext.xml,spring必须要配置的元素有时会要把xml文件集中放在一个地方,这个时候就需要配置下:
web.xml配置的话:

<context-param>  
        <param-name>  
            contextConfigLocation  
        </param-name>  
        <param-value>  
            classpath*:**/*Context.xml  
        </param-value>  
    </context-param>  

web.xml配置的:

public class DefaultConfigration implements WebApplicationInitializer {  
  
    @Override  
    public void onStartup(ServletContext context) throws ServletException {  
        context.addListener(new ContextLoaderListener());  
        context.addListener(new WebAppRootListener());  
        context.setInitParameter("contextConfigLocation", "classpath*:**/*Context.xml");  
    }  
  
}  

相关文章

网友评论

      本文标题:servlet3.0 contextLoadListener

      本文链接:https://www.haomeiwen.com/subject/awtgqttx.html