diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java index 46266135eb4..a195dceb2e3 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java @@ -52,7 +52,6 @@ import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.util.PropertyPlaceholderHelper; import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver; -import org.springframework.web.bind.ServletRequestUtils; import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.View; import org.springframework.web.servlet.view.BeanNameViewResolver; @@ -107,7 +106,7 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom + "

This application has no explicit mapping for /error, so you are seeing this as a fallback.

" + "
${timestamp}
" + "
There was an unexpected error (type=${error}, status=${status}).
" - + "
${message}
" + ""); + + "
${message}
"); @Bean(name = "error") @ConditionalOnMissingBean(name = "error") @@ -157,8 +156,6 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom private final String template; - private final SpelExpressionParser parser = new SpelExpressionParser(); - private final StandardEvaluationContext context = new StandardEvaluationContext(); private PropertyPlaceholderHelper helper; @@ -169,19 +166,7 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom this.template = template; this.context.addPropertyAccessor(new MapAccessor()); this.helper = new PropertyPlaceholderHelper("${", "}"); - this.resolver = new PlaceholderResolver() { - @Override - public String resolvePlaceholder(String name) { - Expression expression = SpelView.this.parser.parseExpression(name); - try { - Object value = expression.getValue(SpelView.this.context); - return (value == null ? null : HtmlUtils.htmlEscape(value.toString())); - } - catch (Exception ex) { - return null; - } - } - }; + this.resolver = new SpelPlaceholderResolver(this.context); } @Override @@ -204,4 +189,31 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom } + /** + * SpEL based {@link PlaceholderResolver}. + */ + private static class SpelPlaceholderResolver implements PlaceholderResolver { + + private final SpelExpressionParser parser = new SpelExpressionParser(); + + private final StandardEvaluationContext context; + + public SpelPlaceholderResolver(StandardEvaluationContext context) { + this.context = context; + } + + @Override + public String resolvePlaceholder(String name) { + Expression expression = this.parser.parseExpression(name); + try { + Object value = expression.getValue(this.context); + return HtmlUtils.htmlEscape(value == null ? null : value.toString()); + } + catch (Exception ex) { + return null; + } + } + + } + } diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java index aaa1299083f..8b465da0a86 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java @@ -222,18 +222,21 @@ public class LoggingApplicationListener implements SmartApplicationListener { Map levels = new RelaxedPropertyResolver(environment) .getSubProperties("logging.level."); for (Entry entry : levels.entrySet()) { - String name = entry.getKey(); - try { - LogLevel level = LogLevel.valueOf(environment.resolvePlaceholders(entry.getValue().toString())); - if (name.equalsIgnoreCase("root")) { - name = null; - } - system.setLogLevel(name, level); - } - catch (RuntimeException e) { - this.logger.error("Cannot set level: " + entry.getValue() + " for '" - + name + "'"); + setLogLevel(system, environment, entry.getKey(), entry.getValue().toString()); + } + } + + private void setLogLevel(LoggingSystem system, Environment environment, String name, + String level) { + try { + if (name.equalsIgnoreCase("root")) { + name = null; } + level = environment.resolvePlaceholders(level); + system.setLogLevel(name, LogLevel.valueOf(level)); + } + catch (RuntimeException ex) { + this.logger.error("Cannot set level: " + level + " for '" + name + "'"); } }