zoukankan      html  css  js  c++  java
  • 获取spring应用中的所有的配置信息

      获取spring应用中所有的配置信息

      前置条件:在一个bean中注入

    @Autowired
    private Environment environment;

    获取方法代码:
    @GetMapping("obtain.environment")
      public R obtainEnvironment() {
        StandardServletEnvironment standardServletEnvironment = (StandardServletEnvironment) environment;
        Map<String, Map<String, String>> map = new HashMap<>(8);
        Iterator<PropertySource<?>> iterator = standardServletEnvironment.getPropertySources().iterator();
        while (iterator.hasNext()) {
          PropertySource<?> source = iterator.next();
          Map<String, String> m = new HashMap<>(128);
          String name = source.getName();
          Object o = source.getSource();
          if (o instanceof Map) {
            for (Map.Entry<String, Object> entry : ((Map<String, Object>) o).entrySet()) {
              String key = entry.getKey();
              m.put(key, standardServletEnvironment.getProperty(key));
            }
          }
          map.put(name, m);
        }
        return R.success(map);
      }
    View Code

      获取:{{url}}/obtain.environment

  • 相关阅读:
    nginx特性
    mysql增删改查
    keepalived+nginx集群
    nginx+tomcat集群方法
    jdk环境配置(Windows)
    nginx_http核心模块(二)
    nginx入门手册(一)
    nginx 配置文件解析(一)
    tcpdump用法
    Tcpdump.
  • 原文地址:https://www.cnblogs.com/wuyouwei/p/10955467.html
Copyright © 2011-2022 走看看