I have defined a with some "common" values. How can I extend the common list by additional values to various new beans?
<util:list id="myCommonList" list-class="java.util.LinkedList"> <bean .../> <bean .../> <bean .../> <bean .../> </util:list> <bean id="extension" parent="myCommonList"> <bean ref="additionalValue"/> </bean>
Will this overwrite the list or extend it?
Spring @Configuration annotation is part of the spring core framework. Spring Configuration annotation indicates that the class has @Bean definition methods. So Spring container can process the class and generate Spring Beans to be used in the application.
You can use properties files, YAML files, environment variables and command-line arguments to externalize configuration. Property values can be injected directly into your beans using the @Value annotation, accessed via Spring's Environment abstraction or bound to structured objects.
You can do it, but not using <util:list>
, which is just a convenience syntax. The container does provide a "collection merging" function, but you have to use the "old" style:
<bean id="parent" class="org.springframework.beans.factory.config.ListFactoryBean"> <property name="sourceList"> <list> <value>X</value> </list> </property> </bean> <bean id="child" parent="parent" class="org.springframework.beans.factory.config.ListFactoryBean"> <property name="sourceList"> <list merge="true"> <value>Y</value> </list> </property> </bean>
Based on skaffman's answer, you can achive this way:
<util:list id="parent"> <value>X</value> </util:list> <bean id="child" parent="parent" class="org.springframework.beans.factory.config.ListFactoryBean"> <property name="sourceList"> <list merge="true"> <value>Y</value> </list> </property> </bean>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With