gpt4 book ai didi

Spring 属性文件为 xml

转载 作者:行者123 更新时间:2023-12-04 17:39:12 25 4
gpt4 key购买 nike

我有属性文件 配置属性在哪里存储了一些应用程序范围的属性。我已经使用属性占位符导入了它:

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

我需要将属性存储在 XML 文件中以传递一些 XML 模式验证。
我的问题是如何在 spring 中将 XML 文件作为属性文件导入,?

谢谢,
阿尔森

最佳答案

PropertyPlaceholderConfigurer 已经通过 DefaultPropertiesPersister 支持 xml 属性文件。

属性的 xml 文件格式如下。

   <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="key1">Value 1</entry>
<entry key="key2">Value 2</entry>
</properties>

您可以使用
  <context:property-placeholder 
location="classpath:/com/myProject/spring_prop.xml" />
<bean id="bean" class="org.MyBean">
<property name="key1" value="${key1}" />
</bean>

关于Spring 属性文件为 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8500351/

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