如何加载jar包中配置文件?多模块如何加载配置文件?jar中配置文件加载失败如何处理?IDEA中创建多模块,WEB模块如何加载子模块中的配置文件?

 工程结构如下:

如上图:

1、创建了一个父模块,和两个子模块,分别为模块模块1和模块2,其中模块1为WEB工程。

2、模块1依赖模块2,启动模块1的时候需要同时加载配置文件1和配置文件2

3、模块2编译后为JAR

4、最初web.xml的配置配置方式为,如下图,classpath只会在classpath中查找,这种方式只会在WEB-INF文件下的XML,不会加载JAR中的XML。导致配置文件2没有成功加载。

5、正确的配置方式为:

<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>

或者

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath*:applicationContext-web.xml,classpath:applicationContext-security.xml
    </param-value>
</context-param>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章