Java 在YML中的接口列表中设置类

Java 在YML中的接口列表中设置类,java,spring-boot,yaml,Java,Spring Boot,Yaml,我有一个带有2个实现的接口。我需要在配置文件中明确设置我将使用的实现。目前,我在启动spring boot应用程序时收到一个错误“原因:元素[api.services[0].ESRIGEOLOCATIONINFERServiceImpl,api.services[1].peliasgeolocationfinderserviceimpl]未绑定”。以下是课程: public interface MyService { // Some methods here } @Data @Com

我有一个带有2个实现的接口。我需要在配置文件中明确设置我将使用的实现。目前,我在启动spring boot应用程序时收到一个错误“原因:元素[api.services[0].ESRIGEOLOCATIONINFERServiceImpl,api.services[1].peliasgeolocationfinderserviceimpl]未绑定”。以下是课程:

public interface MyService {
   // Some methods here
}

 @Data
 @Component
 @NoArgsConstructor
 public class MyFirstServiceImpl implements MyService {

     private String first;
 }

 @Data
 @Component
 @NoArgsConstructor
 public class MySecondServiceImpl implements MyService {
   private String second;
 }

 @Data
 @Configuration
 @EnableConfigurationProperties
 @ConfigurationProperties(prefix="api")
 public class MyConfig {
     @Autowired
     private List<MyService> services;
 }
您知道如何设置接口列表中的值吗


谢谢

您可以通过使用
@组件
@PropertySource(“classpath:api.services[0]”)中的注释来实现这一点


看看这里:

我不确定我是否真的理解了。但是,在添加PropertySource时,我得到:“类路径资源[api.services[0]]无法打开,因为它不存在”。你能给我详细介绍一下你的解决方案吗?
 api:
  services[0]: { first: aValue }
  services[1]: { second: anotherValue }