Spring has ability to initialisate values of core java collection types.
I have a complex collection type Map<String, Set<String>> map
and it inital value defined in spring config:
<bean id="dao" class="ru.mypkg.dao.DaoImpl">
<property name="dataSource" ref="dataSource"/>
<property name="map">
<map>
<entry key="TABLE">
<set>
<value>COMMENT</value>
<value>INDEX</value>
</set>
</entry>
<entry key="VIEW">
<set>
<value>COMMENT</value>
</set>
</entry>
</map>
</property>
</bean>
I want rewrite my config in next manner: Split it on 2 beans for more readability
<bean id="dao" class="ru.mypkg.dao.DaoImpl">
<property name="dataSource" ref="dataSource"/>
<property name="map" ref-id="myMap"/>
</bean>
<bean id="myMap" ..????..>
<entry key="TABLE">
<set>
<value>COMMENT</value>
<value>INDEX</value>
</set>
</entry>
<entry key="VIEW">
<set>
<value>COMMENT</value>
</set>
</entry>
</bean>
Can I achieve that with no creating additional classes?
Here, @Bean instantiates two beans with ids the same as the method names and registers them within the BeanFactory (Spring container) interface. Next, we can initialize the Spring container and request any of the beans from the Spring container. This strategy also makes it simple to achieve dependency injection.
BeanFactory is the actual representation of the Spring IoC container that is responsible for containing and otherwise managing the aforementioned beans. The BeanFactory interface is the central IoC container interface in Spring.
A spring bean can be removed from context by removing its bean definition. BeanDefinitionRegistry factory = (BeanDefinitionRegistry) context. getAutowireCapableBeanFactory(); factory. removeBeanDefinition("mongoRepository");
Certainly, using the <util:map>
namespace. See the Spring documentation C.2.2.5.
Another way to create complex configuration is using the @Configuration approach, or alternatively the FactoryBean interface.
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