Spring ServletContextPlaceholderResolver

  • 类全路径: org.springframework.web.util.ServletContextPropertyUtils.ServletContextPlaceholderResolver
  1. private static class ServletContextPlaceholderResolver
  2. implements PropertyPlaceholderHelper.PlaceholderResolver {
  3. private final String text;
  4. private final ServletContext servletContext;
  5. public ServletContextPlaceholderResolver(String text, ServletContext servletContext) {
  6. this.text = text;
  7. this.servletContext = servletContext;
  8. }
  9. @Override
  10. @Nullable
  11. public String resolvePlaceholder(String placeholderName) {
  12. try {
  13. // servlet 上下文获取
  14. String propVal = this.servletContext.getInitParameter(placeholderName);
  15. if (propVal == null) {
  16. // Fall back to system properties.
  17. propVal = System.getProperty(placeholderName);
  18. if (propVal == null) {
  19. // Fall back to searching the system environment.
  20. propVal = System.getenv(placeholderName);
  21. }
  22. }
  23. return propVal;
  24. }
  25. catch (Throwable ex) {
  26. System.err.println("Could not resolve placeholder '" + placeholderName + "' in [" +
  27. this.text + "] as ServletContext init-parameter or system property: " + ex);
  28. return null;
  29. }
  30. }
  31. }