Spring中WEB.xml配置总结

来源:互联网 发布:中标麒麟 软件源 编辑:程序博客网 时间:2024/05/16 10:39
1. Spring中的web.xml中的配置如下:
Xml代码
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:**/applicationContext-*.xml</param-value>
</context-param>

"**/"表示的是任意目录;
"**/applicationContext-*.xml"表示任意目录下的以"applicationContext-"开头的XML文件。
你自己可以根据需要修改。最好把所有Spring配置文件都放在一个统一的目录下,如:

<!-- Spring 的配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/spring/applicationContext-*.xml</param-value>
</context-param>



web.xml中classpath:和classpath*:, 有什么区别?

classpath:只会到你的class路径中查找找文件;

classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找.


在web.xml里配置Listener

xml 代码如下: 

 

  < listener >  

 

        <listener-class>  org.springframework.web.context.ContextLoaderListener< listener-class>   

 

   < /listener>    

 

如果在web.xml里给该Listener指定要加载的xml,如:

xml代码如下:

<!-- spring config -->

     <context-param>

       <param-name>contextConfigLocation</param-name>  

       <param-value>classpath:applicationContext.xml</param-value>

      </context-param>

则会去加载相应的xml,而不会去加载/WEB-INF/下的applicationContext.xml。

但是,如果没有指定的话,默认会去/WEB-INF/下加载applicationContext.xml。


0 0
原创粉丝点击