工程结构如下:
如上图:
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>