【问题标题】:Spring XML files outside WEB-INFWEB-INF 之外的 Spring XML 文件
【发布时间】:2010-07-19 18:26:52
【问题描述】:

我正在一个使用 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 在演示项目中,spring-services.xml 在服务项目中。 spring-services.xml 文件未加载。我错过了什么吗?

【问题讨论】:

    标签: spring gwt web.xml


    【解决方案1】:

    我猜测演示项目被编译为 WAR,而服务项目被编译为 JAR。另外,presentation 项目依赖于 services 项目。

    在这种情况下,将spring-services.xml 文件作为资源包含在服务项目的 pom 中,以便将其放入其 jar 中,并且由于演示项目依赖于服务项目,因此服务 jar 将放在 @ 987654322@ 文件夹,然后 Spring 将能够从类路径加载它。

    【讨论】:

    • spring-services.xml 已经在 services 项目的 src/main/resources 目录下,所以我想没有必要在项目的 pom 中显式声明它
    【解决方案2】:

    如果该值以classpath: 开头,它将不会在WEB-INF/ 文件夹中查找,它将在类路径中查找,即WEB-INF/classesWEB-INF/lib/ 下所有jar 文件的直接内容。

    要让它看起来在 WEB-INF/ 文件夹中,您需要像这样指定值:

    <param-value>
      /WEB-INF/spring-presentation.xml
      /WEB-INF/spring-services.xml
    </param-value>
    

    (你可以把它们放在一行中,用逗号分隔,但我喜欢这样)

    【讨论】:

      【解决方案3】:

      使用

      &lt;import resource="classpath:spring-services.xml" /&gt;

      spring-presentation.xml 的顶部,而不是从 web.xml 中引用它

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-11-24
        • 2016-09-16
        • 2023-03-14
        • 2015-10-17
        • 1970-01-01
        • 2012-11-27
        • 2015-06-29
        • 2017-07-02
        相关资源
        最近更新 更多