Recycling in the context of the spring application

let's say I have a lot of things in my spring application context that looks like this:

<bean name="foo.0001" class="com.example.MyClass">
    <property name="name" value="foo.name.0001"/>
    <property name="zap">
        <bean class="com.example.Other">
            <property name="name" value="foo.name.0001"/>
        </bean>
    </property>
    <property name="bar">
        <bean class="com.example.NextOther">
            <property name="name" value="foo.name.0001"/>
        </bean>
    </property>
</bean>

therefore, the string foo.name.0001 appears in the bean definition several times. Since this is a larger system with several blocks of this configuration, it is very annoying to change each of these identifiers. Ideally, I would like to install only once per block . Is it possible to set some property that exists only in the local scope of the bean?

+3
source share
2 answers

, , , beans. , Springs PropertyPlaceholderConfigurer. :

<property name="bar">
   <bean class="com.example.NextOther">
      <property name="name" value="${foo.name.001}"/>
   </bean>
</property>

.

+3

, , spring. , beans, -.

xml, bean, beans, .

. :

http://www.javaworld.com/javaworld/jw-02-2008/jw-02-springcomponents.html

, spring xml.

+1

Source: https://habr.com/ru/post/1709866/


All Articles