Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
72dd3b56
Commit
72dd3b56
authored
Jan 11, 2021
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.2.x' into 2.3.x
Closes gh-24747
parents
7625a979
f9e3e0d5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
117 additions
and
71 deletions
+117
-71
WebMvcAutoConfiguration.java
...ot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java
+109
-60
WelcomePageHandlerMapping.java
.../autoconfigure/web/servlet/WelcomePageHandlerMapping.java
+4
-5
WebMvcAutoConfigurationTests.java
...toconfigure/web/servlet/WebMvcAutoConfigurationTests.java
+2
-2
WelcomePageHandlerMappingTests.java
...configure/web/servlet/WelcomePageHandlerMappingTests.java
+2
-4
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java
View file @
72dd3b56
/*
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -17,13 +17,14 @@
...
@@ -17,13 +17,14 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
web
.
servlet
;
package
org
.
springframework
.
boot
.
autoconfigure
.
web
.
servlet
;
import
java.time.Duration
;
import
java.time.Duration
;
import
java.util.
Arrays
;
import
java.util.
HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.ListIterator
;
import
java.util.ListIterator
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.
Optional
;
import
java.util.
Set
;
import
javax.servlet.Servlet
;
import
javax.servlet.Servlet
;
import
javax.servlet.ServletContext
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.logging.LogFactory
;
...
@@ -73,10 +74,10 @@ import org.springframework.core.io.ResourceLoader;
...
@@ -73,10 +74,10 @@ import org.springframework.core.io.ResourceLoader;
import
org.springframework.core.task.AsyncTaskExecutor
;
import
org.springframework.core.task.AsyncTaskExecutor
;
import
org.springframework.format.FormatterRegistry
;
import
org.springframework.format.FormatterRegistry
;
import
org.springframework.format.support.FormattingConversionService
;
import
org.springframework.format.support.FormattingConversionService
;
import
org.springframework.http.CacheControl
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.PathMatcher
;
import
org.springframework.validation.DefaultMessageCodesResolver
;
import
org.springframework.validation.DefaultMessageCodesResolver
;
import
org.springframework.validation.MessageCodesResolver
;
import
org.springframework.validation.MessageCodesResolver
;
import
org.springframework.validation.Validator
;
import
org.springframework.validation.Validator
;
...
@@ -88,11 +89,13 @@ import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
...
@@ -88,11 +89,13 @@ import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
import
org.springframework.web.context.request.NativeWebRequest
;
import
org.springframework.web.context.request.NativeWebRequest
;
import
org.springframework.web.context.request.RequestAttributes
;
import
org.springframework.web.context.request.RequestAttributes
;
import
org.springframework.web.context.request.RequestContextListener
;
import
org.springframework.web.context.request.RequestContextListener
;
import
org.springframework.web.context.support.ServletContextResource
;
import
org.springframework.web.filter.FormContentFilter
;
import
org.springframework.web.filter.FormContentFilter
;
import
org.springframework.web.filter.HiddenHttpMethodFilter
;
import
org.springframework.web.filter.HiddenHttpMethodFilter
;
import
org.springframework.web.filter.RequestContextFilter
;
import
org.springframework.web.filter.RequestContextFilter
;
import
org.springframework.web.servlet.DispatcherServlet
;
import
org.springframework.web.servlet.DispatcherServlet
;
import
org.springframework.web.servlet.HandlerExceptionResolver
;
import
org.springframework.web.servlet.HandlerExceptionResolver
;
import
org.springframework.web.servlet.HandlerMapping
;
import
org.springframework.web.servlet.LocaleResolver
;
import
org.springframework.web.servlet.LocaleResolver
;
import
org.springframework.web.servlet.View
;
import
org.springframework.web.servlet.View
;
import
org.springframework.web.servlet.ViewResolver
;
import
org.springframework.web.servlet.ViewResolver
;
...
@@ -107,6 +110,7 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
...
@@ -107,6 +110,7 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
;
import
org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
;
import
org.springframework.web.servlet.handler.SimpleUrlHandlerMapping
;
import
org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver
;
import
org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver
;
import
org.springframework.web.servlet.i18n.FixedLocaleResolver
;
import
org.springframework.web.servlet.i18n.FixedLocaleResolver
;
import
org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver
;
import
org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver
;
...
@@ -114,6 +118,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
...
@@ -114,6 +118,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
import
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
;
import
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
;
import
org.springframework.web.servlet.resource.AppCacheManifestTransformer
;
import
org.springframework.web.servlet.resource.AppCacheManifestTransformer
;
import
org.springframework.web.servlet.resource.EncodedResourceResolver
;
import
org.springframework.web.servlet.resource.EncodedResourceResolver
;
import
org.springframework.web.servlet.resource.ResourceHttpRequestHandler
;
import
org.springframework.web.servlet.resource.ResourceResolver
;
import
org.springframework.web.servlet.resource.ResourceResolver
;
import
org.springframework.web.servlet.resource.ResourceUrlProvider
;
import
org.springframework.web.servlet.resource.ResourceUrlProvider
;
import
org.springframework.web.servlet.resource.VersionResourceResolver
;
import
org.springframework.web.servlet.resource.VersionResourceResolver
;
...
@@ -155,7 +160,7 @@ public class WebMvcAutoConfiguration {
...
@@ -155,7 +160,7 @@ public class WebMvcAutoConfiguration {
*/
*/
public
static
final
String
DEFAULT_SUFFIX
=
""
;
public
static
final
String
DEFAULT_SUFFIX
=
""
;
private
static
final
String
[]
SERVLET_LOCATIONS
=
{
"/"
}
;
private
static
final
String
SERVLET_LOCATION
=
"/"
;
@Bean
@Bean
@ConditionalOnMissingBean
(
HiddenHttpMethodFilter
.
class
)
@ConditionalOnMissingBean
(
HiddenHttpMethodFilter
.
class
)
...
@@ -171,13 +176,6 @@ public class WebMvcAutoConfiguration {
...
@@ -171,13 +176,6 @@ public class WebMvcAutoConfiguration {
return
new
OrderedFormContentFilter
();
return
new
OrderedFormContentFilter
();
}
}
static
String
[]
getResourceLocations
(
String
[]
staticLocations
)
{
String
[]
locations
=
new
String
[
staticLocations
.
length
+
SERVLET_LOCATIONS
.
length
];
System
.
arraycopy
(
staticLocations
,
0
,
locations
,
0
,
staticLocations
.
length
);
System
.
arraycopy
(
SERVLET_LOCATIONS
,
0
,
locations
,
staticLocations
.
length
,
SERVLET_LOCATIONS
.
length
);
return
locations
;
}
// Defined as a nested config to ensure WebMvcConfigurer is not read when not
// Defined as a nested config to ensure WebMvcConfigurer is not read when not
// on the classpath
// on the classpath
@Configuration
(
proxyBeanMethods
=
false
)
@Configuration
(
proxyBeanMethods
=
false
)
...
@@ -186,10 +184,6 @@ public class WebMvcAutoConfiguration {
...
@@ -186,10 +184,6 @@ public class WebMvcAutoConfiguration {
@Order
(
0
)
@Order
(
0
)
public
static
class
WebMvcAutoConfigurationAdapter
implements
WebMvcConfigurer
{
public
static
class
WebMvcAutoConfigurationAdapter
implements
WebMvcConfigurer
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
WebMvcConfigurer
.
class
);
private
final
ResourceProperties
resourceProperties
;
private
final
WebMvcProperties
mvcProperties
;
private
final
WebMvcProperties
mvcProperties
;
private
final
ListableBeanFactory
beanFactory
;
private
final
ListableBeanFactory
beanFactory
;
...
@@ -202,12 +196,11 @@ public class WebMvcAutoConfiguration {
...
@@ -202,12 +196,11 @@ public class WebMvcAutoConfiguration {
final
ResourceHandlerRegistrationCustomizer
resourceHandlerRegistrationCustomizer
;
final
ResourceHandlerRegistrationCustomizer
resourceHandlerRegistrationCustomizer
;
public
WebMvcAutoConfigurationAdapter
(
ResourceProperties
resourceProperties
,
WebMvcProperties
mvcProperties
,
public
WebMvcAutoConfigurationAdapter
(
WebMvcProperties
mvcProperties
,
ListableBeanFactory
beanFactory
,
ListableBeanFactory
beanFactory
,
ObjectProvider
<
HttpMessageConverters
>
messageConvertersProvider
,
ObjectProvider
<
HttpMessageConverters
>
messageConvertersProvider
,
ObjectProvider
<
ResourceHandlerRegistrationCustomizer
>
resourceHandlerRegistrationCustomizerProvider
,
ObjectProvider
<
ResourceHandlerRegistrationCustomizer
>
resourceHandlerRegistrationCustomizerProvider
,
ObjectProvider
<
DispatcherServletPath
>
dispatcherServletPath
,
ObjectProvider
<
DispatcherServletPath
>
dispatcherServletPath
,
ObjectProvider
<
ServletRegistrationBean
<?>>
servletRegistrations
)
{
ObjectProvider
<
ServletRegistrationBean
<?>>
servletRegistrations
)
{
this
.
resourceProperties
=
resourceProperties
;
this
.
mvcProperties
=
mvcProperties
;
this
.
mvcProperties
=
mvcProperties
;
this
.
beanFactory
=
beanFactory
;
this
.
beanFactory
=
beanFactory
;
this
.
messageConvertersProvider
=
messageConvertersProvider
;
this
.
messageConvertersProvider
=
messageConvertersProvider
;
...
@@ -328,37 +321,6 @@ public class WebMvcAutoConfiguration {
...
@@ -328,37 +321,6 @@ public class WebMvcAutoConfiguration {
ApplicationConversionService
.
addBeans
(
registry
,
this
.
beanFactory
);
ApplicationConversionService
.
addBeans
(
registry
,
this
.
beanFactory
);
}
}
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
if
(!
this
.
resourceProperties
.
isAddMappings
())
{
logger
.
debug
(
"Default resource handling disabled"
);
return
;
}
Duration
cachePeriod
=
this
.
resourceProperties
.
getCache
().
getPeriod
();
CacheControl
cacheControl
=
this
.
resourceProperties
.
getCache
().
getCachecontrol
().
toHttpCacheControl
();
if
(!
registry
.
hasMappingForPattern
(
"/webjars/**"
))
{
customizeResourceHandlerRegistration
(
registry
.
addResourceHandler
(
"/webjars/**"
)
.
addResourceLocations
(
"classpath:/META-INF/resources/webjars/"
)
.
setCachePeriod
(
getSeconds
(
cachePeriod
)).
setCacheControl
(
cacheControl
));
}
String
staticPathPattern
=
this
.
mvcProperties
.
getStaticPathPattern
();
if
(!
registry
.
hasMappingForPattern
(
staticPathPattern
))
{
customizeResourceHandlerRegistration
(
registry
.
addResourceHandler
(
staticPathPattern
)
.
addResourceLocations
(
getResourceLocations
(
this
.
resourceProperties
.
getStaticLocations
()))
.
setCachePeriod
(
getSeconds
(
cachePeriod
)).
setCacheControl
(
cacheControl
));
}
}
private
Integer
getSeconds
(
Duration
cachePeriod
)
{
return
(
cachePeriod
!=
null
)
?
(
int
)
cachePeriod
.
getSeconds
()
:
null
;
}
private
void
customizeResourceHandlerRegistration
(
ResourceHandlerRegistration
registration
)
{
if
(
this
.
resourceHandlerRegistrationCustomizer
!=
null
)
{
this
.
resourceHandlerRegistrationCustomizer
.
customize
(
registration
);
}
}
@Bean
@Bean
@ConditionalOnMissingBean
({
RequestContextListener
.
class
,
RequestContextFilter
.
class
})
@ConditionalOnMissingBean
({
RequestContextListener
.
class
,
RequestContextFilter
.
class
})
@ConditionalOnMissingFilterBean
(
RequestContextFilter
.
class
)
@ConditionalOnMissingFilterBean
(
RequestContextFilter
.
class
)
...
@@ -374,22 +336,31 @@ public class WebMvcAutoConfiguration {
...
@@ -374,22 +336,31 @@ public class WebMvcAutoConfiguration {
@Configuration
(
proxyBeanMethods
=
false
)
@Configuration
(
proxyBeanMethods
=
false
)
public
static
class
EnableWebMvcConfiguration
extends
DelegatingWebMvcConfiguration
implements
ResourceLoaderAware
{
public
static
class
EnableWebMvcConfiguration
extends
DelegatingWebMvcConfiguration
implements
ResourceLoaderAware
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
WebMvcConfigurer
.
class
);
private
final
ResourceProperties
resourceProperties
;
private
final
ResourceProperties
resourceProperties
;
private
final
WebMvcProperties
mvcProperties
;
private
final
WebMvcProperties
mvcProperties
;
private
final
ListableBeanFactory
beanFactory
;
private
final
WebMvcRegistrations
mvcRegistrations
;
private
final
WebMvcRegistrations
mvcRegistrations
;
private
final
ResourceHandlerRegistrationCustomizer
resourceHandlerRegistrationCustomizer
;
private
ResourceLoader
resourceLoader
;
private
ResourceLoader
resourceLoader
;
private
final
ListableBeanFactory
beanFactory
;
private
final
Set
<
String
>
autoConfiguredResourceHandlers
=
new
HashSet
<>();
public
EnableWebMvcConfiguration
(
ResourceProperties
resourceProperties
,
public
EnableWebMvcConfiguration
(
ResourceProperties
resourceProperties
,
ObjectProvider
<
WebMvcProperties
>
mvcPropertiesProvider
,
ObjectProvider
<
WebMvcProperties
>
mvcPropertiesProvider
,
ObjectProvider
<
WebMvcRegistrations
>
mvcRegistrationsProvider
,
ListableBeanFactory
beanFactory
)
{
ObjectProvider
<
WebMvcRegistrations
>
mvcRegistrationsProvider
,
ObjectProvider
<
ResourceHandlerRegistrationCustomizer
>
resourceHandlerRegistrationCustomizerProvider
,
ListableBeanFactory
beanFactory
)
{
this
.
resourceProperties
=
resourceProperties
;
this
.
resourceProperties
=
resourceProperties
;
this
.
mvcProperties
=
mvcPropertiesProvider
.
getIfAvailable
();
this
.
mvcProperties
=
mvcPropertiesProvider
.
getIfAvailable
();
this
.
mvcRegistrations
=
mvcRegistrationsProvider
.
getIfUnique
();
this
.
mvcRegistrations
=
mvcRegistrationsProvider
.
getIfUnique
();
this
.
resourceHandlerRegistrationCustomizer
=
resourceHandlerRegistrationCustomizerProvider
.
getIfAvailable
();
this
.
beanFactory
=
beanFactory
;
this
.
beanFactory
=
beanFactory
;
}
}
...
@@ -429,6 +400,72 @@ public class WebMvcAutoConfiguration {
...
@@ -429,6 +400,72 @@ public class WebMvcAutoConfiguration {
resourceUrlProvider
);
resourceUrlProvider
);
}
}
@Bean
@Override
public
HandlerMapping
resourceHandlerMapping
(
UrlPathHelper
urlPathHelper
,
PathMatcher
pathMatcher
,
ContentNegotiationManager
contentNegotiationManager
,
FormattingConversionService
conversionService
,
ResourceUrlProvider
resourceUrlProvider
)
{
HandlerMapping
mapping
=
super
.
resourceHandlerMapping
(
urlPathHelper
,
pathMatcher
,
contentNegotiationManager
,
conversionService
,
resourceUrlProvider
);
if
(
mapping
instanceof
SimpleUrlHandlerMapping
)
{
addServletContextResourceHandlerMapping
((
SimpleUrlHandlerMapping
)
mapping
);
}
return
mapping
;
}
private
void
addServletContextResourceHandlerMapping
(
SimpleUrlHandlerMapping
mapping
)
{
Map
<
String
,
?>
urlMap
=
mapping
.
getUrlMap
();
String
pattern
=
this
.
mvcProperties
.
getStaticPathPattern
();
Object
handler
=
urlMap
.
get
(
pattern
);
if
(
handler
instanceof
ResourceHttpRequestHandler
&&
this
.
autoConfiguredResourceHandlers
.
contains
(
pattern
))
{
addServletContextResourceHandlerMapping
((
ResourceHttpRequestHandler
)
handler
);
}
}
private
void
addServletContextResourceHandlerMapping
(
ResourceHttpRequestHandler
handler
)
{
ServletContext
servletContext
=
getServletContext
();
if
(
servletContext
!=
null
)
{
List
<
Resource
>
locations
=
handler
.
getLocations
();
locations
.
add
(
new
ServletContextResource
(
servletContext
,
SERVLET_LOCATION
));
}
}
@Override
protected
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
super
.
addResourceHandlers
(
registry
);
if
(!
this
.
resourceProperties
.
isAddMappings
())
{
logger
.
debug
(
"Default resource handling disabled"
);
return
;
}
addResourceHandler
(
registry
,
"/webjars/**"
,
"classpath:/META-INF/resources/webjars/"
);
addResourceHandler
(
registry
,
this
.
mvcProperties
.
getStaticPathPattern
(),
this
.
resourceProperties
.
getStaticLocations
());
}
private
void
addResourceHandler
(
ResourceHandlerRegistry
registry
,
String
pattern
,
String
...
locations
)
{
if
(
registry
.
hasMappingForPattern
(
pattern
))
{
return
;
}
ResourceHandlerRegistration
registration
=
registry
.
addResourceHandler
(
pattern
);
registration
.
addResourceLocations
(
locations
);
registration
.
setCachePeriod
(
getSeconds
(
this
.
resourceProperties
.
getCache
().
getPeriod
()));
registration
.
setCacheControl
(
this
.
resourceProperties
.
getCache
().
getCachecontrol
().
toHttpCacheControl
());
customizeResourceHandlerRegistration
(
registration
);
this
.
autoConfiguredResourceHandlers
.
add
(
pattern
);
}
private
Integer
getSeconds
(
Duration
cachePeriod
)
{
return
(
cachePeriod
!=
null
)
?
(
int
)
cachePeriod
.
getSeconds
()
:
null
;
}
private
void
customizeResourceHandlerRegistration
(
ResourceHandlerRegistration
registration
)
{
if
(
this
.
resourceHandlerRegistrationCustomizer
!=
null
)
{
this
.
resourceHandlerRegistrationCustomizer
.
customize
(
registration
);
}
}
@Bean
@Bean
public
WelcomePageHandlerMapping
welcomePageHandlerMapping
(
ApplicationContext
applicationContext
,
public
WelcomePageHandlerMapping
welcomePageHandlerMapping
(
ApplicationContext
applicationContext
,
FormattingConversionService
mvcConversionService
,
ResourceUrlProvider
mvcResourceUrlProvider
)
{
FormattingConversionService
mvcConversionService
,
ResourceUrlProvider
mvcResourceUrlProvider
)
{
...
@@ -440,22 +477,34 @@ public class WebMvcAutoConfiguration {
...
@@ -440,22 +477,34 @@ public class WebMvcAutoConfiguration {
return
welcomePageHandlerMapping
;
return
welcomePageHandlerMapping
;
}
}
private
Optional
<
Resource
>
getWelcomePage
()
{
private
Resource
getWelcomePage
()
{
String
[]
locations
=
getResourceLocations
(
this
.
resourceProperties
.
getStaticLocations
());
for
(
String
location
:
this
.
resourceProperties
.
getStaticLocations
())
{
return
Arrays
.
stream
(
locations
).
map
(
this
::
getIndexHtml
).
filter
(
this
::
isReadable
).
findFirst
();
Resource
indexHtml
=
getIndexHtml
(
location
);
if
(
indexHtml
!=
null
)
{
return
indexHtml
;
}
}
ServletContext
servletContext
=
getServletContext
();
if
(
servletContext
!=
null
)
{
return
getIndexHtml
(
new
ServletContextResource
(
servletContext
,
SERVLET_LOCATION
));
}
return
null
;
}
}
private
Resource
getIndexHtml
(
String
location
)
{
private
Resource
getIndexHtml
(
String
location
)
{
return
this
.
resourceLoader
.
getResource
(
location
+
"index.html"
);
return
getIndexHtml
(
this
.
resourceLoader
.
getResource
(
location
)
);
}
}
private
boolean
isReadable
(
Resource
resource
)
{
private
Resource
getIndexHtml
(
Resource
location
)
{
try
{
try
{
return
resource
.
exists
()
&&
(
resource
.
getURL
()
!=
null
);
Resource
resource
=
location
.
createRelative
(
"index.html"
);
if
(
resource
.
exists
()
&&
(
resource
.
getURL
()
!=
null
))
{
return
resource
;
}
}
}
catch
(
Exception
ex
)
{
catch
(
Exception
ex
)
{
return
false
;
}
}
return
null
;
}
}
@Bean
@Bean
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WelcomePageHandlerMapping.java
View file @
72dd3b56
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
21
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.web.servlet;
...
@@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.web.servlet;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
...
@@ -49,9 +48,9 @@ final class WelcomePageHandlerMapping extends AbstractUrlHandlerMapping {
...
@@ -49,9 +48,9 @@ final class WelcomePageHandlerMapping extends AbstractUrlHandlerMapping {
private
static
final
List
<
MediaType
>
MEDIA_TYPES_ALL
=
Collections
.
singletonList
(
MediaType
.
ALL
);
private
static
final
List
<
MediaType
>
MEDIA_TYPES_ALL
=
Collections
.
singletonList
(
MediaType
.
ALL
);
WelcomePageHandlerMapping
(
TemplateAvailabilityProviders
templateAvailabilityProviders
,
WelcomePageHandlerMapping
(
TemplateAvailabilityProviders
templateAvailabilityProviders
,
ApplicationContext
applicationContext
,
Optional
<
Resource
>
welcomePage
,
String
staticPathPattern
)
{
ApplicationContext
applicationContext
,
Resource
welcomePage
,
String
staticPathPattern
)
{
if
(
welcomePage
.
isPresent
()
&&
"/**"
.
equals
(
staticPathPattern
))
{
if
(
welcomePage
!=
null
&&
"/**"
.
equals
(
staticPathPattern
))
{
logger
.
info
(
"Adding welcome page: "
+
welcomePage
.
get
()
);
logger
.
info
(
"Adding welcome page: "
+
welcomePage
);
setRootViewName
(
"forward:index.html"
);
setRootViewName
(
"forward:index.html"
);
}
}
else
if
(
welcomeTemplateExists
(
templateAvailabilityProviders
,
applicationContext
))
{
else
if
(
welcomeTemplateExists
(
templateAvailabilityProviders
,
applicationContext
))
{
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java
View file @
72dd3b56
/*
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -913,7 +913,7 @@ class WebMvcAutoConfigurationTests {
...
@@ -913,7 +913,7 @@ class WebMvcAutoConfigurationTests {
protected
Map
<
String
,
List
<
Resource
>>
getResourceMappingLocations
(
ApplicationContext
context
)
{
protected
Map
<
String
,
List
<
Resource
>>
getResourceMappingLocations
(
ApplicationContext
context
)
{
Object
bean
=
context
.
getBean
(
"resourceHandlerMapping"
);
Object
bean
=
context
.
getBean
(
"resourceHandlerMapping"
);
if
(
bean
instanceof
HandlerMapping
)
{
if
(
bean
instanceof
HandlerMapping
)
{
return
getMappingLocations
(
context
.
getBean
(
"resourceHandlerMapping"
,
HandlerMapping
.
class
)
);
return
getMappingLocations
(
(
HandlerMapping
)
bean
);
}
}
assertThat
(
bean
.
toString
()).
isEqualTo
(
"null"
);
assertThat
(
bean
.
toString
()).
isEqualTo
(
"null"
);
return
Collections
.
emptyMap
();
return
Collections
.
emptyMap
();
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WelcomePageHandlerMappingTests.java
View file @
72dd3b56
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
21
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.web.servlet;
...
@@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.web.servlet;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Optional
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
...
@@ -162,8 +161,7 @@ class WelcomePageHandlerMappingTests {
...
@@ -162,8 +161,7 @@ class WelcomePageHandlerMappingTests {
return
new
WelcomePageHandlerMapping
(
return
new
WelcomePageHandlerMapping
(
templateAvailabilityProviders
templateAvailabilityProviders
.
getIfAvailable
(()
->
new
TemplateAvailabilityProviders
(
applicationContext
)),
.
getIfAvailable
(()
->
new
TemplateAvailabilityProviders
(
applicationContext
)),
applicationContext
,
Optional
.
ofNullable
(
staticIndexPage
.
getIfAvailable
()),
staticPathPattern
);
applicationContext
,
staticIndexPage
.
getIfAvailable
(),
staticPathPattern
);
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment