0

есть property файл со следующим содержимым

client.properties файл:

   id=1
    name=John Smith
    greeting=hello there!

Использую его в определении бинов:

   <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

        <property name="locations">
            <list>
                <value>classpath:client.properties</value>
            </list>
        </property>
    </bean>



 <bean class="Client" id="client">
        <constructor-arg value="${id}"/>
        <constructor-arg value="${name}"/>
 </bean>

Теперь я хочу подключить еще 1 property файл с такими же клячами, но разынми значениями

annotatedClient.properties:

id=2
name=Vasiliy

Как их правильно различать?

делаю следующим образом:

 <property name="locations">
            <list>
                <value>classpath:client.properties</value>
                <value>classpath:annotaitedClient.properties</value>
            </list>
        </property>

так выбрасывается exeption(

Could not resolve placeholder 'client.id' in string value "${client.id}"

):

   <bean class="Client" id="client">
        <constructor-arg value="${client.id}"/>
        <constructor-arg value="${client.name}"/>
     <property name="greeting" value="${greeting}"/>
    </bean>

так читается только файл annotaitedClent.properties:

   <bean class="Client" id="client">
        <constructor-arg value="${id}"/>
        <constructor-arg value="${name}"/>
     <property name="greeting" value="${greeting}"/>
    </bean>
0

1 ответ 1

1

Попробуй так:

<util:properties id="clientProps" location="classpath:client.properties"></util:properties>
<util:properties id="annotaitedClientProps" location="classpath:annotaitedClient.properties"></util:properties>
<bean id="allProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="propertiesArray">
        <list>
            <ref bean="clientProps"></ref>
            <ref bean="annotaitedClientProps"></ref>
        </list>
    </property>
</bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="properties" ref="allProperties"></property>
</bean>

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими пользовательским соглашением, политикой конфиденциальности и политикой о куки

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.