Hatem
Hatem

Reputation: 369

Import XML beans file from another module?

I am using multi-module Spring Project built using Apache Maven. I have some XML beans located in the resources folder of the module (1). I wanna to import them into another XML beans file which is located in module (2).

What I know, is that I have to use:

<import resource="" /> 

What is the correct way to write the path in the resource attribute? With examples if possible.

Upvotes: 1

Views: 5673

Answers (1)

qingbo
qingbo

Reputation: 2160

<import resource="classpath:resources/beans-config.xml" />

The XML file should be in WEB-INF/resources folder of the referenced module(1).

Check out the note in Composing XML-based configuration metadata.

Of course to be able to reference a classpath resource from another module, you have to add a dependency section in module 2's pom.xml like:

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

Module 1 jar will be in classpath when module 2 app is run, or be packaged into war if module 2 is a webapp.

Upvotes: 1

Related Questions