Spring属性文件为xml

Ars*_*yan 5 spring

我有属性文件config.properties,其中存储了一些应用程序范围的属性.我使用属性占位符导入它:

<context:property-placeholder location="classpath:/config.properties" />
Run Code Online (Sandbox Code Playgroud)

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

谢谢,阿森

Ara*_*d A 6

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>
Run Code Online (Sandbox Code Playgroud)

您可以使用

  <context:property-placeholder 
  location="classpath:/com/myProject/spring_prop.xml" />
      <bean id="bean" class="org.MyBean">
         <property name="key1" value="${key1}" />
      </bean>
Run Code Online (Sandbox Code Playgroud)