52
52
import org .springframework .expression .spel .support .StandardEvaluationContext ;
53
53
import org .springframework .util .PropertyPlaceholderHelper ;
54
54
import org .springframework .util .PropertyPlaceholderHelper .PlaceholderResolver ;
55
- import org .springframework .web .bind .ServletRequestUtils ;
56
55
import org .springframework .web .servlet .DispatcherServlet ;
57
56
import org .springframework .web .servlet .View ;
58
57
import org .springframework .web .servlet .view .BeanNameViewResolver ;
@@ -107,7 +106,7 @@ protected static class WhitelabelErrorViewConfiguration {
107
106
+ "<p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p>"
108
107
+ "<div id='created'>${timestamp}</div>"
109
108
+ "<div>There was an unexpected error (type=${error}, status=${status}).</div>"
110
- + "<div>${message}</div>" + " </body></html>" );
109
+ + "<div>${message}</div></body></html>" );
111
110
112
111
@ Bean (name = "error" )
113
112
@ ConditionalOnMissingBean (name = "error" )
@@ -157,8 +156,6 @@ private static class SpelView implements View {
157
156
158
157
private final String template ;
159
158
160
- private final SpelExpressionParser parser = new SpelExpressionParser ();
161
-
162
159
private final StandardEvaluationContext context = new StandardEvaluationContext ();
163
160
164
161
private PropertyPlaceholderHelper helper ;
@@ -169,19 +166,7 @@ public SpelView(String template) {
169
166
this .template = template ;
170
167
this .context .addPropertyAccessor (new MapAccessor ());
171
168
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 );
185
170
}
186
171
187
172
@ Override
@@ -204,4 +189,31 @@ public void render(Map<String, ?> model, HttpServletRequest request,
204
189
205
190
}
206
191
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
+
207
219
}
0 commit comments