简体   繁体   中英

Relative paths in spring classpath resource

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?

一个简短的补充:如果你想从jar访问资源,它应该是:

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

目录

If it can help you ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM