5252import org .springframework .expression .spel .support .StandardEvaluationContext ;
5353import org .springframework .util .PropertyPlaceholderHelper ;
5454import org .springframework .util .PropertyPlaceholderHelper .PlaceholderResolver ;
55- import org .springframework .web .bind .ServletRequestUtils ;
5655import org .springframework .web .servlet .DispatcherServlet ;
5756import org .springframework .web .servlet .View ;
5857import 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}
0 commit comments