Get all the configuration information for spring applications
Preconditions: injecting a bean,
@Autowired
Private Environment Environment;
acquisition method code:
@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); }
Get: {{url}} / obtain.environment