Reputation: 4936
I'm wondering if if (and how) I could use relative classpath resource paths within spring. I've following application structure:
src/
org/me/
mainContext.xml
app1/
app1Context.xml
app2/
app2Context.xml
comp1/
comp1Context.xml
Now in mainContext.xml
I'd like to import bean definitions by relative paths:
<import resource="classpath:app1/app1Context.xml"/>
<import resource="classpath:app2/app2Context.xml"/>
and similary in app2Context.xml
:
<import resource="classpath:comp1/comp1Context.xml"/>
(The org.me.app2
code is in different jar (WEB-INF/lib/app2.jar
)).
However currently I'm getting FileNotFoundException exception:
java.io.FileNotFoundException: class path resource [app1/app1Context.xml] cannot be opened because it does not exist
Can I use such relative paths? How? To which path are relative classpath paths resolved?
There is a similar question (Relative paths in spring classpath resource) but people are only suggesting what I'm already doing (and what doesn't work right now).
Upvotes: 0
Views: 7803
Reputation: 120771
There is a similar question (Relative paths in spring classpath resource) but people are only suggesting what I'm already doing (and what doesn't work right now).
That is wrong: The people answered with paths that are relative to the classpath root, but not relative to the location of the xml! (*You should notice that the example in "Relative paths in spring classpath resource" is a maven project, so the folder resources become the classpath root)
So if you want to use the same technique then the imports would be (with org/me
):
<import resource="classpath:org/me/app1/app1Context.xml"/>
<import resource="classpath:org/me/app2/app2Context.xml"/>
Upvotes: 1