@@ -167,13 +167,20 @@ public OrderedFormContentFilter formContentFilter() {
167
167
return new OrderedFormContentFilter ();
168
168
}
169
169
170
+ static String [] getResourceLocations (String [] staticLocations ) {
171
+ String [] locations = new String [staticLocations .length + SERVLET_LOCATIONS .length ];
172
+ System .arraycopy (staticLocations , 0 , locations , 0 , staticLocations .length );
173
+ System .arraycopy (SERVLET_LOCATIONS , 0 , locations , staticLocations .length , SERVLET_LOCATIONS .length );
174
+ return locations ;
175
+ }
176
+
170
177
// Defined as a nested config to ensure WebMvcConfigurer is not read when not
171
178
// on the classpath
172
179
@ Configuration
173
180
@ Import (EnableWebMvcConfiguration .class )
174
181
@ EnableConfigurationProperties ({ WebMvcProperties .class , ResourceProperties .class })
175
182
@ Order (0 )
176
- public static class WebMvcAutoConfigurationAdapter implements WebMvcConfigurer , ResourceLoaderAware {
183
+ public static class WebMvcAutoConfigurationAdapter implements WebMvcConfigurer {
177
184
178
185
private static final Log logger = LogFactory .getLog (WebMvcConfigurer .class );
179
186
@@ -187,8 +194,6 @@ public static class WebMvcAutoConfigurationAdapter implements WebMvcConfigurer,
187
194
188
195
final ResourceHandlerRegistrationCustomizer resourceHandlerRegistrationCustomizer ;
189
196
190
- private ResourceLoader resourceLoader ;
191
-
192
197
public WebMvcAutoConfigurationAdapter (ResourceProperties resourceProperties , WebMvcProperties mvcProperties ,
193
198
ListableBeanFactory beanFactory , ObjectProvider <HttpMessageConverters > messageConvertersProvider ,
194
199
ObjectProvider <ResourceHandlerRegistrationCustomizer > resourceHandlerRegistrationCustomizerProvider ) {
@@ -199,11 +204,6 @@ public WebMvcAutoConfigurationAdapter(ResourceProperties resourceProperties, Web
199
204
this .resourceHandlerRegistrationCustomizer = resourceHandlerRegistrationCustomizerProvider .getIfAvailable ();
200
205
}
201
206
202
- @ Override
203
- public void setResourceLoader (ResourceLoader resourceLoader ) {
204
- this .resourceLoader = resourceLoader ;
205
- }
206
-
207
207
@ Override
208
208
public void configureMessageConverters (List <HttpMessageConverter <?>> converters ) {
209
209
this .messageConvertersProvider
@@ -338,37 +338,6 @@ private Integer getSeconds(Duration cachePeriod) {
338
338
return (cachePeriod != null ) ? (int ) cachePeriod .getSeconds () : null ;
339
339
}
340
340
341
- @ Bean
342
- public WelcomePageHandlerMapping welcomePageHandlerMapping (ApplicationContext applicationContext ) {
343
- return new WelcomePageHandlerMapping (new TemplateAvailabilityProviders (applicationContext ),
344
- applicationContext , getWelcomePage (), this .mvcProperties .getStaticPathPattern ());
345
- }
346
-
347
- static String [] getResourceLocations (String [] staticLocations ) {
348
- String [] locations = new String [staticLocations .length + SERVLET_LOCATIONS .length ];
349
- System .arraycopy (staticLocations , 0 , locations , 0 , staticLocations .length );
350
- System .arraycopy (SERVLET_LOCATIONS , 0 , locations , staticLocations .length , SERVLET_LOCATIONS .length );
351
- return locations ;
352
- }
353
-
354
- private Optional <Resource > getWelcomePage () {
355
- String [] locations = getResourceLocations (this .resourceProperties .getStaticLocations ());
356
- return Arrays .stream (locations ).map (this ::getIndexHtml ).filter (this ::isReadable ).findFirst ();
357
- }
358
-
359
- private Resource getIndexHtml (String location ) {
360
- return this .resourceLoader .getResource (location + "index.html" );
361
- }
362
-
363
- private boolean isReadable (Resource resource ) {
364
- try {
365
- return resource .exists () && (resource .getURL () != null );
366
- }
367
- catch (Exception ex ) {
368
- return false ;
369
- }
370
- }
371
-
372
341
private void customizeResourceHandlerRegistration (ResourceHandlerRegistration registration ) {
373
342
if (this .resourceHandlerRegistrationCustomizer != null ) {
374
343
this .resourceHandlerRegistrationCustomizer .customize (registration );
@@ -430,16 +399,22 @@ private List<Resource> resolveFaviconLocations() {
430
399
* Configuration equivalent to {@code @EnableWebMvc}.
431
400
*/
432
401
@ Configuration
433
- public static class EnableWebMvcConfiguration extends DelegatingWebMvcConfiguration {
402
+ public static class EnableWebMvcConfiguration extends DelegatingWebMvcConfiguration implements ResourceLoaderAware {
403
+
404
+ private final ResourceProperties resourceProperties ;
434
405
435
406
private final WebMvcProperties mvcProperties ;
436
407
437
408
private final ListableBeanFactory beanFactory ;
438
409
439
410
private final WebMvcRegistrations mvcRegistrations ;
440
411
441
- public EnableWebMvcConfiguration (ObjectProvider <WebMvcProperties > mvcPropertiesProvider ,
412
+ private ResourceLoader resourceLoader ;
413
+
414
+ public EnableWebMvcConfiguration (ResourceProperties resourceProperties ,
415
+ ObjectProvider <WebMvcProperties > mvcPropertiesProvider ,
442
416
ObjectProvider <WebMvcRegistrations > mvcRegistrationsProvider , ListableBeanFactory beanFactory ) {
417
+ this .resourceProperties = resourceProperties ;
443
418
this .mvcProperties = mvcPropertiesProvider .getIfAvailable ();
444
419
this .mvcRegistrations = mvcRegistrationsProvider .getIfUnique ();
445
420
this .beanFactory = beanFactory ;
@@ -470,6 +445,33 @@ public RequestMappingHandlerMapping requestMappingHandlerMapping() {
470
445
return super .requestMappingHandlerMapping ();
471
446
}
472
447
448
+ @ Bean
449
+ public WelcomePageHandlerMapping welcomePageHandlerMapping (ApplicationContext applicationContext ) {
450
+ WelcomePageHandlerMapping welcomePageHandlerMapping = new WelcomePageHandlerMapping (
451
+ new TemplateAvailabilityProviders (applicationContext ), applicationContext , getWelcomePage (),
452
+ this .mvcProperties .getStaticPathPattern ());
453
+ welcomePageHandlerMapping .setInterceptors (getInterceptors ());
454
+ return welcomePageHandlerMapping ;
455
+ }
456
+
457
+ private Optional <Resource > getWelcomePage () {
458
+ String [] locations = getResourceLocations (this .resourceProperties .getStaticLocations ());
459
+ return Arrays .stream (locations ).map (this ::getIndexHtml ).filter (this ::isReadable ).findFirst ();
460
+ }
461
+
462
+ private Resource getIndexHtml (String location ) {
463
+ return this .resourceLoader .getResource (location + "index.html" );
464
+ }
465
+
466
+ private boolean isReadable (Resource resource ) {
467
+ try {
468
+ return resource .exists () && (resource .getURL () != null );
469
+ }
470
+ catch (Exception ex ) {
471
+ return false ;
472
+ }
473
+ }
474
+
473
475
@ Bean
474
476
@ Override
475
477
public FormattingConversionService mvcConversionService () {
@@ -543,6 +545,11 @@ public ContentNegotiationManager mvcContentNegotiationManager() {
543
545
return manager ;
544
546
}
545
547
548
+ @ Override
549
+ public void setResourceLoader (ResourceLoader resourceLoader ) {
550
+ this .resourceLoader = resourceLoader ;
551
+ }
552
+
546
553
}
547
554
548
555
@ Configuration
0 commit comments