@@ -160,13 +160,20 @@ public OrderedFormContentFilter formContentFilter() {
160
160
return new OrderedFormContentFilter ();
161
161
}
162
162
163
+ static String [] getResourceLocations (String [] staticLocations ) {
164
+ String [] locations = new String [staticLocations .length + SERVLET_LOCATIONS .length ];
165
+ System .arraycopy (staticLocations , 0 , locations , 0 , staticLocations .length );
166
+ System .arraycopy (SERVLET_LOCATIONS , 0 , locations , staticLocations .length , SERVLET_LOCATIONS .length );
167
+ return locations ;
168
+ }
169
+
163
170
// Defined as a nested config to ensure WebMvcConfigurer is not read when not
164
171
// on the classpath
165
172
@ Configuration (proxyBeanMethods = false )
166
173
@ Import (EnableWebMvcConfiguration .class )
167
174
@ EnableConfigurationProperties ({ WebMvcProperties .class , ResourceProperties .class })
168
175
@ Order (0 )
169
- public static class WebMvcAutoConfigurationAdapter implements WebMvcConfigurer , ResourceLoaderAware {
176
+ public static class WebMvcAutoConfigurationAdapter implements WebMvcConfigurer {
170
177
171
178
private static final Log logger = LogFactory .getLog (WebMvcConfigurer .class );
172
179
@@ -180,8 +187,6 @@ public static class WebMvcAutoConfigurationAdapter implements WebMvcConfigurer,
180
187
181
188
final ResourceHandlerRegistrationCustomizer resourceHandlerRegistrationCustomizer ;
182
189
183
- private ResourceLoader resourceLoader ;
184
-
185
190
public WebMvcAutoConfigurationAdapter (ResourceProperties resourceProperties , WebMvcProperties mvcProperties ,
186
191
ListableBeanFactory beanFactory , ObjectProvider <HttpMessageConverters > messageConvertersProvider ,
187
192
ObjectProvider <ResourceHandlerRegistrationCustomizer > resourceHandlerRegistrationCustomizerProvider ) {
@@ -192,11 +197,6 @@ public WebMvcAutoConfigurationAdapter(ResourceProperties resourceProperties, Web
192
197
this .resourceHandlerRegistrationCustomizer = resourceHandlerRegistrationCustomizerProvider .getIfAvailable ();
193
198
}
194
199
195
- @ Override
196
- public void setResourceLoader (ResourceLoader resourceLoader ) {
197
- this .resourceLoader = resourceLoader ;
198
- }
199
-
200
200
@ Override
201
201
public void configureMessageConverters (List <HttpMessageConverter <?>> converters ) {
202
202
this .messageConvertersProvider
@@ -319,37 +319,6 @@ private Integer getSeconds(Duration cachePeriod) {
319
319
return (cachePeriod != null ) ? (int ) cachePeriod .getSeconds () : null ;
320
320
}
321
321
322
- @ Bean
323
- public WelcomePageHandlerMapping welcomePageHandlerMapping (ApplicationContext applicationContext ) {
324
- return new WelcomePageHandlerMapping (new TemplateAvailabilityProviders (applicationContext ),
325
- applicationContext , getWelcomePage (), this .mvcProperties .getStaticPathPattern ());
326
- }
327
-
328
- static String [] getResourceLocations (String [] staticLocations ) {
329
- String [] locations = new String [staticLocations .length + SERVLET_LOCATIONS .length ];
330
- System .arraycopy (staticLocations , 0 , locations , 0 , staticLocations .length );
331
- System .arraycopy (SERVLET_LOCATIONS , 0 , locations , staticLocations .length , SERVLET_LOCATIONS .length );
332
- return locations ;
333
- }
334
-
335
- private Optional <Resource > getWelcomePage () {
336
- String [] locations = getResourceLocations (this .resourceProperties .getStaticLocations ());
337
- return Arrays .stream (locations ).map (this ::getIndexHtml ).filter (this ::isReadable ).findFirst ();
338
- }
339
-
340
- private Resource getIndexHtml (String location ) {
341
- return this .resourceLoader .getResource (location + "index.html" );
342
- }
343
-
344
- private boolean isReadable (Resource resource ) {
345
- try {
346
- return resource .exists () && (resource .getURL () != null );
347
- }
348
- catch (Exception ex ) {
349
- return false ;
350
- }
351
- }
352
-
353
322
private void customizeResourceHandlerRegistration (ResourceHandlerRegistration registration ) {
354
323
if (this .resourceHandlerRegistrationCustomizer != null ) {
355
324
this .resourceHandlerRegistrationCustomizer .customize (registration );
@@ -382,16 +351,22 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
382
351
* Configuration equivalent to {@code @EnableWebMvc}.
383
352
*/
384
353
@ Configuration (proxyBeanMethods = false )
385
- public static class EnableWebMvcConfiguration extends DelegatingWebMvcConfiguration {
354
+ public static class EnableWebMvcConfiguration extends DelegatingWebMvcConfiguration implements ResourceLoaderAware {
355
+
356
+ private final ResourceProperties resourceProperties ;
386
357
387
358
private final WebMvcProperties mvcProperties ;
388
359
389
360
private final ListableBeanFactory beanFactory ;
390
361
391
362
private final WebMvcRegistrations mvcRegistrations ;
392
363
393
- public EnableWebMvcConfiguration (ObjectProvider <WebMvcProperties > mvcPropertiesProvider ,
364
+ private ResourceLoader resourceLoader ;
365
+
366
+ public EnableWebMvcConfiguration (ResourceProperties resourceProperties ,
367
+ ObjectProvider <WebMvcProperties > mvcPropertiesProvider ,
394
368
ObjectProvider <WebMvcRegistrations > mvcRegistrationsProvider , ListableBeanFactory beanFactory ) {
369
+ this .resourceProperties = resourceProperties ;
395
370
this .mvcProperties = mvcPropertiesProvider .getIfAvailable ();
396
371
this .mvcRegistrations = mvcRegistrationsProvider .getIfUnique ();
397
372
this .beanFactory = beanFactory ;
@@ -428,6 +403,34 @@ public RequestMappingHandlerMapping requestMappingHandlerMapping(
428
403
mvcResourceUrlProvider );
429
404
}
430
405
406
+ @ Bean
407
+ public WelcomePageHandlerMapping welcomePageHandlerMapping (ApplicationContext applicationContext ,
408
+ FormattingConversionService mvcConversionService , ResourceUrlProvider mvcResourceUrlProvider ) {
409
+ WelcomePageHandlerMapping welcomePageHandlerMapping = new WelcomePageHandlerMapping (
410
+ new TemplateAvailabilityProviders (applicationContext ), applicationContext , getWelcomePage (),
411
+ this .mvcProperties .getStaticPathPattern ());
412
+ welcomePageHandlerMapping .setInterceptors (getInterceptors (mvcConversionService , mvcResourceUrlProvider ));
413
+ return welcomePageHandlerMapping ;
414
+ }
415
+
416
+ private Optional <Resource > getWelcomePage () {
417
+ String [] locations = getResourceLocations (this .resourceProperties .getStaticLocations ());
418
+ return Arrays .stream (locations ).map (this ::getIndexHtml ).filter (this ::isReadable ).findFirst ();
419
+ }
420
+
421
+ private Resource getIndexHtml (String location ) {
422
+ return this .resourceLoader .getResource (location + "index.html" );
423
+ }
424
+
425
+ private boolean isReadable (Resource resource ) {
426
+ try {
427
+ return resource .exists () && (resource .getURL () != null );
428
+ }
429
+ catch (Exception ex ) {
430
+ return false ;
431
+ }
432
+ }
433
+
431
434
@ Bean
432
435
@ Override
433
436
public FormattingConversionService mvcConversionService () {
@@ -499,6 +502,11 @@ public ContentNegotiationManager mvcContentNegotiationManager() {
499
502
return manager ;
500
503
}
501
504
505
+ @ Override
506
+ public void setResourceLoader (ResourceLoader resourceLoader ) {
507
+ this .resourceLoader = resourceLoader ;
508
+ }
509
+
502
510
}
503
511
504
512
@ Configuration (proxyBeanMethods = false )
0 commit comments