简体   繁体   English

spring classpath资源中的相对路径

[英]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. 我有一堆spring配置文件,所有这些文件都存放在各种子包中的META-INF目录下。 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. 当我在jar文件之外使用本地构建时,这很好用。 But when I package everything up in a jar then I get an error that it cannot resolve the URL resource. 但是,当我将所有内容打包在一个jar中时,我得到一个错误,它无法解析URL资源。 If I change the above to an absolute path (with classpath:) then it works fine. 如果我将上面的内容更改为绝对路径(使用classpath :),那么它可以正常工作。

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 : 在我的项目中正常工作的是app-servlet.xml中的以下行:

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

目录

If it can help you ... 如果它可以帮助你......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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