Spring MapPropertySource

  • Author: HuiFer
  • 源码阅读仓库: SourceHot-spring

  • 类全路径: org.springframework.core.env.MapPropertySource

  • 内部数据结构是一个Map<String,Object> 这是一个对 map 的操作.
  • 整体代码如下.
  1. public class MapPropertySource extends EnumerablePropertySource<Map<String, Object>> {
  2. public MapPropertySource(String name, Map<String, Object> source) {
  3. super(name, source);
  4. }
  5. @Override
  6. @Nullable
  7. public Object getProperty(String name) {
  8. // 从map中获取 name 对应的value
  9. return this.source.get(name);
  10. }
  11. @Override
  12. public boolean containsProperty(String name) {
  13. // 判断是否存在 name 属性
  14. return this.source.containsKey(name);
  15. }
  16. @Override
  17. public String[] getPropertyNames() {
  18. // 互殴去 map 的所有key
  19. return StringUtils.toStringArray(this.source.keySet());
  20. }
  21. }