[英]Spring: migrate XML config to Annotation for util:map
我在XML文件中具有以下Spring配置:
<util:map id="myService">
<entry key="s1" value-ref="goodService" />
<entry key="s2" value-ref="betterService" />
</util:map>
有沒有辦法將其遷移到基於注釋的配置,即
@Bean
public Map<String, MyService> serviceMap() {
Map<String, MyService> map = new HashMap<>();
...
因此, 映射中的值是對bean的引用。
在config類中,自動裝配實例並將屬性放置到地圖上
@Autowired
private GoodService goodService;
@Autowired
private BetterService betterService;
@Bean
public Map<String, MyService> serviceMap() {
Map<String, MyService> map = new HashMap<>();
map.put("s1", goodService);
map.put("s2", betterService);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.