从类路径上的jar文件导入Spring属性文件 [英] Importing Spring properties files from jar file on classpath

查看:147
本文介绍了从类路径上的jar文件导入Spring属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想导入 src / main / resource .properties 结尾>我项目的 ALL jar依赖项的位置。

I want to import all property files, ending on .properties that are contained in the src/main/resource locations of ALL jar-dependencies my project has.

我写了一个JUnit测试,其中我的context.xml位于src / test / resources文件夹。我使用通配符指定了property-placeholder,但它不起作用。

I wrote a JUnit test, where my context.xml is located in the src/test/resources folder. I specified the property-placeholder using wildcards, but it doesn't work.

<context:property-placeholder location="classpath*:*.properties"/>

可能我是傻瓜,但我找不到网上问题的解决方案。这里有没有人知道什么是正确的语法?

May be I am to stupid, but I could not find a solution to my problem on the net. Does anyone here know what is the correct syntax?

编辑:

root项目,有maven依赖项,从我的工作区解析:

The root project, has maven dependencies, that are resolved from my workspace:

我想导入依赖项目的module.properties文件:

And i want to import the module.properties files of the dependent projects:

推荐答案

从Spring 文档


classpath *:前缀也可以与其余的PathMatcher模式结合使用位置路径,例如classpath *:META-INF / * - beans.xml。 [...]

The " classpath*:" prefix can also be combined with a PathMatcher pattern in the rest of the location path, for example " classpath*:META-INF/*-beans.xml". [...]

但是有一个限制:


请注意,类路径*:与Ant样式模式结合使用时,只能在模式启动前与至少一个根目录可靠地工作,除非实际目标文件驻留在文件系统中。这意味着像classpath *:*。xml这样的模式不会从jar文件的根目录中检索文件,而只能从扩展目录的根目录中检索文件。 [...]

Please note that " classpath*:" when combined with Ant-style patterns will only work reliably with at least one root directory before the pattern starts, unless the actual target files reside in the file system. This means that a pattern like " classpath*:*.xml" will not retrieve files from the root of jar files but rather only from the root of expanded directories. [...]

因此,如果我将模块的属性文件放在src / main / resources / META-INF中,我可以加载其中如下:

So if I place my module's property files in src/main/resources/META-INF, I can load of them as follows:

<context:property-placeholder location="classpath*:/META-INF/*.properties" />

这篇关于从类路径上的jar文件导入Spring属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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