Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring:将XML配置迁移到util:map的注释_Java_Spring_Spring Boot_Spring Annotations - Fatal编程技术网

Java Spring:将XML配置迁移到util:map的注释

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

我在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的引用。

在配置类中,自动连接实例并将属性放置到映射中

@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);