【问题标题】:Import XML beans file from another module?从另一个模块导入 XML bean 文件?
【发布时间】:2014-11-22 04:36:05
【问题描述】:

我正在使用使用 Apache Maven 构建的多模块 Spring 项目。我在模块 (1) 的资源文件夹中有一些 XML bean。我想将它们导入到位于模块 (2) 中的另一个 XML bean 文件中。

我所知道的是,我必须使用:

<import resource="" /> 

在资源属性中写入路径的正确方法是什么?如有可能,请提供示例。

【问题讨论】:

    标签: xml spring apache javabeans


    【解决方案1】:
    <import resource="classpath:resources/beans-config.xml" />
    

    XML 文件应位于引用模块 (1) 的 WEB-INF/resources 文件夹中。

    查看Composing XML-based configuration metadata中的注释。

    当然,为了能够从另一个模块引用类路径资源,您必须在模块 2 的 pom.xml 中添加一个依赖部分,例如:

        <dependency>
            <groupId>module1.groupid</groupId>
            <artifactId>module-1-artifact-id</artifactId>
            <version>module1.version</version>
        </dependency>
    

    当模块 2 应用程序运行时,模块 1 jar 将位于类路径中,如果模块 2 是 web 应用程序,则将其打包到 war 中。

    【讨论】:

    • import 标签如何知道 bean 文件位于 module(1) 中?您没有在路径中提及与该模块相关的任何内容!官方文档对这部分的主题太差了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-15
    • 2018-08-09
    相关资源
    最近更新 更多