开发者

Relative paths in spring classpath resource

I have a bunch of spring config files, all of wh开发者_JAVA百科ich live under the META-INF directory in various subpackages. I have been using import like the following...

  <import resource="../database/schema.xml"/>

So a relative path from the source file. This works fine when I am working with a local build outside of a jar file. But when I package everything up in a jar then I get an error that it cannot resolve the URL resource. If I change the above to an absolute path (with classpath:) then it works fine.

Is there any way to use relative paths with ".." in when the configs are packaged in a jar or am I restricted to descending relative paths and absolute paths only?


A short addition: If you want to access the resources from a jar, it should read:

<import resource="classpath*:database/schema.xml"/>


<import resource="classpath:database/schema.xml"/>


What works fine on my project is the following lines in the app-servlet.xml :

<!-- Database Configuration -->
<import resource="classpath*:/database/DataSource.xml"/>
<import resource="classpath*:/database/Hibernate.xml"/>

Relative paths in spring classpath resource

If it can help you ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜