@@ -132,29 +132,29 @@ public class RequestContext {
132
132
* Create a new RequestContext for the given request, using the request attributes for Errors retrieval.
133
133
* <p>This only works with InternalResourceViews, as Errors instances are part of the model and not
134
134
* normally exposed as request attributes. It will typically be used within JSPs or custom tags.
135
- * <p><b>Will only work within a DispatcherServlet request.</b>
136
- * Pass in a ServletContext to be able to fall back to the root WebApplicationContext .
135
+ * <p>As of 6.2, this will work within a DispatcherServlet request as well as with the root
136
+ * WebApplicationContext (outside a DispatcherServlet) .
137
137
* @param request current HTTP request
138
138
* @see org.springframework.web.servlet.DispatcherServlet
139
139
* @see #RequestContext(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.ServletContext)
140
140
*/
141
141
public RequestContext (HttpServletRequest request ) {
142
- this (request , null , null , null );
142
+ this (request , null , request . getServletContext () , null );
143
143
}
144
144
145
145
/**
146
146
* Create a new RequestContext for the given request, using the request attributes for Errors retrieval.
147
147
* <p>This only works with InternalResourceViews, as Errors instances are part of the model and not
148
148
* normally exposed as request attributes. It will typically be used within JSPs or custom tags.
149
- * <p><b>Will only work within a DispatcherServlet request.</b>
150
- * Pass in a ServletContext to be able to fall back to the root WebApplicationContext .
149
+ * <p>As of 6.2, this will work within a DispatcherServlet request as well as with the root
150
+ * WebApplicationContext (outside a DispatcherServlet) .
151
151
* @param request current HTTP request
152
152
* @param response current HTTP response
153
153
* @see org.springframework.web.servlet.DispatcherServlet
154
154
* @see #RequestContext(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse, jakarta.servlet.ServletContext, Map)
155
155
*/
156
156
public RequestContext (HttpServletRequest request , HttpServletResponse response ) {
157
- this (request , response , null , null );
157
+ this (request , response , request . getServletContext () , null );
158
158
}
159
159
160
160
/**
@@ -176,16 +176,16 @@ public RequestContext(HttpServletRequest request, @Nullable ServletContext servl
176
176
/**
177
177
* Create a new RequestContext for the given request, using the given model attributes for Errors retrieval.
178
178
* <p>This works with all View implementations. It will typically be used by View implementations.
179
- * <p><b>Will only work within a DispatcherServlet request.</b>
180
- * Pass in a ServletContext to be able to fall back to the root WebApplicationContext .
179
+ * <p>As of 6.2, this will work within a DispatcherServlet request as well as with the root
180
+ * WebApplicationContext (outside a DispatcherServlet) .
181
181
* @param request current HTTP request
182
182
* @param model the model attributes for the current view (can be {@code null},
183
183
* using the request attributes for Errors retrieval)
184
184
* @see org.springframework.web.servlet.DispatcherServlet
185
185
* @see #RequestContext(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse, jakarta.servlet.ServletContext, Map)
186
186
*/
187
187
public RequestContext (HttpServletRequest request , @ Nullable Map <String , Object > model ) {
188
- this (request , null , null , model );
188
+ this (request , null , request . getServletContext () , model );
189
189
}
190
190
191
191
/**
@@ -281,13 +281,6 @@ public final WebApplicationContext getWebApplicationContext() {
281
281
return this .webApplicationContext ;
282
282
}
283
283
284
- /**
285
- * Return the current WebApplicationContext as MessageSource.
286
- */
287
- public final MessageSource getMessageSource () {
288
- return this .webApplicationContext ;
289
- }
290
-
291
284
/**
292
285
* Return the model Map that this RequestContext encapsulates, if any.
293
286
* @return the populated model Map, or {@code null} if none available
@@ -297,13 +290,22 @@ public final Map<String, Object> getModel() {
297
290
return this .model ;
298
291
}
299
292
293
+ /**
294
+ * Return the MessageSource to use (typically the current WebApplicationContext).
295
+ * <p>Note: As of 6.2, this method is non-final and therefore overridable.
296
+ */
297
+ public MessageSource getMessageSource () {
298
+ return this .webApplicationContext ;
299
+ }
300
+
300
301
/**
301
302
* Return the current Locale (falling back to the request locale; never {@code null}).
302
303
* <p>Typically coming from a DispatcherServlet's {@link LocaleResolver}.
303
304
* Also includes a fallback check for JSTL's Locale attribute.
305
+ * <p>Note: As of 6.2, this method is non-final and therefore overridable.
304
306
* @see RequestContextUtils#getLocale
305
307
*/
306
- public final Locale getLocale () {
308
+ public Locale getLocale () {
307
309
return (this .locale != null ? this .locale : getFallbackLocale ());
308
310
}
309
311
0 commit comments