弹簧集合合并 [英] Spring collection merge
本文介绍了弹簧集合合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个FactoryBean生成两个列表,我想用这两个合并版本初始化一个bean。有这样做吗?
< bean id =listAclass =XFactoryBean>
...
< / bean>
< bean id =listBclass =YFactoryBean>
...
< / bean>
< bean>
< property name =AwithB...>
< / bean>
有一个解决方案适用于静态列表( http://vikdor.blogspot.hu/2012/10/using-collection-merging-in-
解决方案
Java @Configuration
FTW:
@Configuration
public class Config {
@Resource
private List listA;
@Resource
private List listB;
@Bean
public List AwithB(){
List mergedList = new ArrayList(listA);
listB.addAll(listB);
return mergedList;
}
}
>
I have two lists generated with a FactoryBean and I would like to initialize a bean with the merged version of this two. Is there a way doing this?
<bean id="listA" class="XFactoryBean" >
...
</bean>
<bean id="listB" class="YFactoryBean">
...
</bean>
<bean >
<property name="AwithB" ...>
</bean>
There is a solution that works with static lists (http://vikdor.blogspot.hu/2012/10/using-collection-merging-in-spring-to.html), but does not work with those generated lists.
解决方案
Java @Configuration
FTW:
@Configuration
public class Config {
@Resource
private List listA;
@Resource
private List listB;
@Bean
public List AwithB() {
List mergedList = new ArrayList(listA);
listB.addAll(listB);
return mergedList;
}
}
Much less boilerplate.
这篇关于弹簧集合合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文