zl程序教程

您现在的位置是:首页 >  后端

当前栏目

web.xml中的contextConfigLocation在spring中的作用

SpringWebXML 作用
2023-09-11 14:14:57 时间

在web.xml中通过contextConfigLocation配置spring,

contextConfigLocation参数定义了要装入的 Spring 配置文件。默认会去/WEB-INF/下加载applicationContext.xml。

如果想装入多个配置文件,可以在 <param-value>标记中用逗号作分隔符或通配符。

 

在web.xml里配置Listener

web.xml 代码如下:  

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/app-*.xml</param-value>
</context-param>

app-context.xml

<context:component-scan base-package="com.xdt.ibs" />