Spring属性文件作为XML [英] Spring properties file as xml

查看:101
本文介绍了Spring属性文件作为XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have properties file config.properties where are stored some application wide properties. And I have imported it using property placeholder:

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

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

I need to store properties in XML file to pass some XML schema validations. My question is how to import XML file as properties file in spring,?

谢谢, 阿森

推荐答案

PropertyPlaceholderConfigurer已经通过

PropertyPlaceholderConfigurer already supports xml property files via the DefaultPropertiesPersister

属性的xml文件格式如下.

The xml file format for the properties is as below.

   <?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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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