首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

Spring contextConfigLocation[通俗易懂]

spring如何使用多个xml配置文件 1, 在web.xml中定义 contextConfigLocation参数.spring会使用这个参数加载.所有逗号分割的xml.如果没有这个参数,spring默认加载web-inf/applicationContext.xml文件. 例如: <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:conf/spring/applicationContext_core*.xml, classpath*:conf/spring/applicationContext_dict*.xml, classpath*:conf/spring/applicationContext_hibernate.xml, </param-value> </context-param> contextConfigLocation 参数定义了要装入的 Spring 配置文件。 原理:利用ServletContextListener 实现。 Spring 提供ServletContextListener 的一个实现类ContextLoaderListener ,该类可以作为listener 使用,它会在创建时自动查找WEB-INF/ 下的applicationContext.xrnl 文件。因此,如果只有一个配置文件,并且文件名为applicationContext.xml ,则只需在web.xml文件中增加如下代码即可: <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>

02
领券