Relative paths in spring classpath resource

2019-04-29 10:34发布

I have a bunch of spring config files, all of which 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?

Thanks.

3条回答
smile是对你的礼貌
2楼-- · 2019-04-29 11:05
<import resource="classpath:database/schema.xml"/>
查看更多
Lonely孤独者°
3楼-- · 2019-04-29 11:14

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"/>

Directories

If it can help you ...

查看更多
聊天终结者
4楼-- · 2019-04-29 11:26

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

<import resource="classpath*:database/schema.xml"/>
查看更多
登录 后发表回答