Relative paths in spring classpath resource

戏子无情 提交于 2019-12-07 06:10:40

问题


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?


回答1:


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

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



回答2:


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



回答3:


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 ...



来源:https://stackoverflow.com/questions/1601106/relative-paths-in-spring-classpath-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!