yaml配置对象map

yaml配置如下:

objectConfig:
  object-map:
    1:
      name: "对象一"
      desc: "这是第一个对象"
      url: "https://abc.abc.abc"
    2:
      name: "对象二"
      desc: "这是第二个对象"
      url: "https://abc.abc.abc"

Java配置类代码如下:

@Configuration
@RefreshScope
@ConfigurationProperties(prefix = "objectConfig")
public class ObjectConfig {
  private Map objectMap;
}

  public static class ObjectEntity{
    private String name;
    private String desc;
    private String url;
  }
}

Java使用代码如下:

@Autowired
private ObjectConfig objectConfig;

ObjectConfig.ObjectEntity objectEntity = objectConfig.getObjectMap().get(1);

你可能感兴趣的:(yaml配置对象map)