我在一个使用 Spring 和 GWT 的多模块 maven2 项目中工作。假设我有两个子项目:服务和演示。 “service”包含服务的实际实现,“presentation”负责为 GWT 包装它们。
我已经成功加载了 WEB-INF 目录中的 Spring XML 文件(与 web.xml 相同),但是我遇到了应该从其他模块加载的那些 XML 文件的问题。
我的 web.xml 如下所示:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/spring-presentation.xml, classpath:/spring-services.xml
</param-value>
</context-param>
这里的spring-presentation.xml
在presentation项目中,spring-services.xml
在service项目中。
未加载 spring-services.xml
文件。我错过了什么吗?
最佳答案
我猜测演示项目被编译为 WAR,而服务项目被编译为 JAR。此外,演示项目依赖于服务项目。
在这种情况下,将 spring-services.xml
文件作为资源包含在服务项目的 pom 中,以便将其放入其 jar 中,并且由于演示项目依赖于服务项目,服务 jar 将放在 /WEB-INF/lib
文件夹中,然后 Spring 将能够从类路径加载它。
关于WEB-INF 之外的 Spring XML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3283884/