Spring SystemPropertyPlaceholderResolver

  • 类全路径: org.springframework.util.SystemPropertyUtils.SystemPropertyPlaceholderResolver
  1. private static class SystemPropertyPlaceholderResolver implements PropertyPlaceholderHelper.PlaceholderResolver {
  2. private final String text;
  3. public SystemPropertyPlaceholderResolver(String text) {
  4. this.text = text;
  5. }
  6. @Override
  7. @Nullable
  8. public String resolvePlaceholder(String placeholderName) {
  9. try {
  10. String propVal = System.getProperty(placeholderName);
  11. if (propVal == null) {
  12. // Fall back to searching the system environment.
  13. // 获取系统属性
  14. propVal = System.getenv(placeholderName);
  15. }
  16. return propVal;
  17. }
  18. catch (Throwable ex) {
  19. System.err.println("Could not resolve placeholder '" + placeholderName + "' in [" +
  20. this.text + "] as system property: " + ex);
  21. return null;
  22. }
  23. }
  24. }