mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Polish
This commit is contained in:
parent
7e842aee77
commit
6009f41782
@ -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
|
||||
+ "<p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p>"
|
||||
+ "<div id='created'>${timestamp}</div>"
|
||||
+ "<div>There was an unexpected error (type=${error}, status=${status}).</div>"
|
||||
+ "<div>${message}</div>" + "</body></html>");
|
||||
+ "<div>${message}</div></body></html>");
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -222,18 +222,21 @@ public class LoggingApplicationListener implements SmartApplicationListener {
|
||||
Map<String, Object> levels = new RelaxedPropertyResolver(environment)
|
||||
.getSubProperties("logging.level.");
|
||||
for (Entry<String, Object> 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 + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user