在springbeans.xml中使用Java util属性而不是propertyplaceholder configurator

时间:2016-04-05 06:34:51

标签: java spring properties spring-properties

我需要使用Java.util.properties而不是Spring Eg中的PropertyPlaceHolderConfigurator动态地在springbeans.xml中存放属性值。

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="location" value="file:test.properties" />
 </bean>   
<bean id="dbconnectionFactory" class="com.test.Test">           
      <property name="username" value="${username}" />
      <property name="password" value="${password}" />
 </bean>

我可以使用java.util.properties来模仿相同的结果,即

<bean id="javaproperty" class="java.util.Properties">
                                   <property name="location" value="file:test.properties" />
            </bean> 

            <bean id="dbconnectionFactory"
                        class="con.test.Test">

              <property name="username" value="${username}" />
                        <property name="password" value="${password}" />
            </bean>

1 个答案:

答案 0 :(得分:1)

由于你已经在使用Spring,你可以做到

public sealed class Person : KnowYourCustomerBase
{
     [DataMember]
     public string Surname { get; set; }

     [DataMember]
     public string FirstName { get; set; }

     [DataMember]
     public string MiddleName { get; set; }

     [DataMember]
     public string Address4 { get; set; }

     [DataMember]
     public string DateOfBirth { get; set; }

     [DataMember]
     public string NationalID { get; set; }

     [DataMember]
     public string Gender { get; set; }
}

然后只需注入它,它的类型为<bean id="properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="locations"> <list> <value>classpath*:application.properties</value> </list> </property> </bean

java.util.properties