gpt4 book ai didi

java - 使用 Spring 和 Webapp 属性占位符查找属性

转载 作者:行者123 更新时间:2023-11-30 06:35:03 25 4
gpt4 key购买 nike

这是一个“简单”的问题,我正在寻找操作方法和/或你是笨蛋不要那样做。我对两者都持开放态度。

我正在构建一个 war 文件并希望结构为:

WEB-INF/
properties/
<my properties files>
classes/
...
spring/
<my spring files>

是傻子吗?我知道我可以通过属性占位符访问属性文件,但我不想将属性嵌套在类部分中 - 这对我来说没有意义。

所以 Spring 文件看起来像这样:

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

如果我想在类区域访问它们。我以为

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

让我直接将目录放在 WEB-INF 下...我错了吗(ps 我想我是:))。

有什么建议吗?

最佳答案

这应该可行

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

WEB-INF 不是 web-app 的根,所以你需要在路径中添加 WEB-INF。

spring-context-3.1.xsd

<xsd:attribute name="location" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
<![CDATA[
The location of the properties file to resolve placeholders against, as a Spring
resource location: a URL, a "classpath:" pseudo URL, or a relative file path.
Multiple locations may be specified, separated by commas. If neither location nor properties-ref is
specified, placeholders will be resolved against system properties.


]]>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>

关于java - 使用 Spring 和 Webapp 属性占位符查找属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6472483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com