You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
source-code-hunter/docs/Spring/clazz/PlaceholderResolver/Spring-ServletContextPlaceh...

1.2 KiB

Spring ServletContextPlaceholderResolver

  • 类全路径: org.springframework.web.util.ServletContextPropertyUtils.ServletContextPlaceholderResolver
	private static class ServletContextPlaceholderResolver
			implements PropertyPlaceholderHelper.PlaceholderResolver {

		private final String text;

		private final ServletContext servletContext;

		public ServletContextPlaceholderResolver(String text, ServletContext servletContext) {
			this.text = text;
			this.servletContext = servletContext;
		}

		@Override
		@Nullable
		public String resolvePlaceholder(String placeholderName) {
			try {
				// servlet 上下文获取
				String propVal = this.servletContext.getInitParameter(placeholderName);
				if (propVal == null) {
					// Fall back to system properties.
					propVal = System.getProperty(placeholderName);
					if (propVal == null) {
						// Fall back to searching the system environment.
						propVal = System.getenv(placeholderName);
					}
				}
				return propVal;
			}
			catch (Throwable ex) {
				System.err.println("Could not resolve placeholder '" + placeholderName + "' in [" +
						this.text + "] as ServletContext init-parameter or system property: " + ex);
				return null;
			}
		}
	}