Java Spring:将XML配置迁移到util:map的注释
我在XML文件中有以下Spring配置:Java Spring:将XML配置迁移到util:map的注释,java,spring,spring-boot,spring-annotations,Java,Spring,Spring Boot,Spring Annotations,我在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> serviceM
<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的引用。在配置类中,自动连接实例并将属性放置到映射中
@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);