Skip to content

Commit 6009f41

Browse files
committed
Polish
1 parent 7e842ae commit 6009f41

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import org.springframework.expression.spel.support.StandardEvaluationContext;
5353
import org.springframework.util.PropertyPlaceholderHelper;
5454
import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver;
55-
import org.springframework.web.bind.ServletRequestUtils;
5655
import org.springframework.web.servlet.DispatcherServlet;
5756
import org.springframework.web.servlet.View;
5857
import org.springframework.web.servlet.view.BeanNameViewResolver;
@@ -107,7 +106,7 @@ protected static class WhitelabelErrorViewConfiguration {
107106
+ "<p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p>"
108107
+ "<div id='created'>${timestamp}</div>"
109108
+ "<div>There was an unexpected error (type=${error}, status=${status}).</div>"
110-
+ "<div>${message}</div>" + "</body></html>");
109+
+ "<div>${message}</div></body></html>");
111110

112111
@Bean(name = "error")
113112
@ConditionalOnMissingBean(name = "error")
@@ -157,8 +156,6 @@ private static class SpelView implements View {
157156

158157
private final String template;
159158

160-
private final SpelExpressionParser parser = new SpelExpressionParser();
161-
162159
private final StandardEvaluationContext context = new StandardEvaluationContext();
163160

164161
private PropertyPlaceholderHelper helper;
@@ -169,19 +166,7 @@ public SpelView(String template) {
169166
this.template = template;
170167
this.context.addPropertyAccessor(new MapAccessor());
171168
this.helper = new PropertyPlaceholderHelper("${", "}");
172-
this.resolver = new PlaceholderResolver() {
173-
@Override
174-
public String resolvePlaceholder(String name) {
175-
Expression expression = SpelView.this.parser.parseExpression(name);
176-
try {
177-
Object value = expression.getValue(SpelView.this.context);
178-
return (value == null ? null : HtmlUtils.htmlEscape(value.toString()));
179-
}
180-
catch (Exception ex) {
181-
return null;
182-
}
183-
}
184-
};
169+
this.resolver = new SpelPlaceholderResolver(this.context);
185170
}
186171

187172
@Override
@@ -204,4 +189,31 @@ public void render(Map<String, ?> model, HttpServletRequest request,
204189

205190
}
206191

192+
/**
193+
* SpEL based {@link PlaceholderResolver}.
194+
*/
195+
private static class SpelPlaceholderResolver implements PlaceholderResolver {
196+
197+
private final SpelExpressionParser parser = new SpelExpressionParser();
198+
199+
private final StandardEvaluationContext context;
200+
201+
public SpelPlaceholderResolver(StandardEvaluationContext context) {
202+
this.context = context;
203+
}
204+
205+
@Override
206+
public String resolvePlaceholder(String name) {
207+
Expression expression = this.parser.parseExpression(name);
208+
try {
209+
Object value = expression.getValue(this.context);
210+
return HtmlUtils.htmlEscape(value == null ? null : value.toString());
211+
}
212+
catch (Exception ex) {
213+
return null;
214+
}
215+
}
216+
217+
}
218+
207219
}

spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,21 @@ public void setLogLevels(LoggingSystem system, Environment environment) {
222222
Map<String, Object> levels = new RelaxedPropertyResolver(environment)
223223
.getSubProperties("logging.level.");
224224
for (Entry<String, Object> entry : levels.entrySet()) {
225-
String name = entry.getKey();
226-
try {
227-
LogLevel level = LogLevel.valueOf(environment.resolvePlaceholders(entry.getValue().toString()));
228-
if (name.equalsIgnoreCase("root")) {
229-
name = null;
230-
}
231-
system.setLogLevel(name, level);
232-
}
233-
catch (RuntimeException e) {
234-
this.logger.error("Cannot set level: " + entry.getValue() + " for '"
235-
+ name + "'");
225+
setLogLevel(system, environment, entry.getKey(), entry.getValue().toString());
226+
}
227+
}
228+
229+
private void setLogLevel(LoggingSystem system, Environment environment, String name,
230+
String level) {
231+
try {
232+
if (name.equalsIgnoreCase("root")) {
233+
name = null;
236234
}
235+
level = environment.resolvePlaceholders(level);
236+
system.setLogLevel(name, LogLevel.valueOf(level));
237+
}
238+
catch (RuntimeException ex) {
239+
this.logger.error("Cannot set level: " + level + " for '" + name + "'");
237240
}
238241
}
239242

0 commit comments

Comments
 (0)