WEB-INF/web.xml文件中:
<!-- 上下文参数 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:applicationContext_*.xml</param-value> </context-param> <!-- 监听器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 默认找 /WEB-INF/[servlet的名称]-servlet.xml --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc.xml</param-value> </init-param> </servlet>
1:当classpath不加*的时候表示引用当前项目类路径下满足条件的文件
2:当classpath加*的时候表示引用当前项目或者所引用jar包里面满足条件的文件
注意:特别是第二点,在maven项目中经常引入jar包,把配置文件放在jar包里的,这一点非常重要。否则引入不成功。
进一步了解关于classpath的深度阅读:SpringMVC xml文件路径在web.xml中的配置
---------------------
原作者:lw670020705
原文:https://blog.csdn.net/lw670020705/article/details/82082433
浙公网安备 33010602011771号