spring classpath资源中的相对路径 [英] Relative paths in spring classpath resource

查看:497
本文介绍了spring classpath资源中的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆spring配置文件,所有这些文件都存放在各种子包中的META-INF目录下。我一直在使用以下导入...

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

所以来自源文件的相对路径。当我在jar文件之外使用本地构建时,这很好用。但是,当我将所有内容打包在一个jar中时,我得到一个错误,它无法解析URL资源。如果我将上面的内容更改为绝对路径(使用classpath :),那么它可以正常工作。

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.

有什么方法可以使用带有..的相对路径configs是打包在jar中还是仅限于降序相对路径和绝对路径?

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访问资源,它应该是:

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

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

这篇关于spring classpath资源中的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆