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
cc855f44
Commit
cc855f44
authored
Oct 06, 2017
by
Bruce Brouwer
Committed by
Andy Wilkinson
Nov 21, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Auto-configure templated welcome page
See gh-10545
parent
08c85c1f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
9 deletions
+35
-9
WebMvcAutoConfiguration.java
...ot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java
+8
-2
WelcomePageHandlerMapping.java
.../autoconfigure/web/servlet/WelcomePageHandlerMapping.java
+27
-7
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java
View file @
cc855f44
...
@@ -48,6 +48,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
...
@@ -48,6 +48,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type
;
import
org.springframework.boot.autoconfigure.http.HttpMessageConverters
;
import
org.springframework.boot.autoconfigure.http.HttpMessageConverters
;
import
org.springframework.boot.autoconfigure.template.TemplateAvailabilityProviders
;
import
org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration
;
import
org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration
;
import
org.springframework.boot.autoconfigure.validation.ValidatorAdapter
;
import
org.springframework.boot.autoconfigure.validation.ValidatorAdapter
;
import
org.springframework.boot.autoconfigure.web.ConditionalOnEnabledResourceChain
;
import
org.springframework.boot.autoconfigure.web.ConditionalOnEnabledResourceChain
;
...
@@ -57,6 +58,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
...
@@ -57,6 +58,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import
org.springframework.boot.web.servlet.filter.OrderedHiddenHttpMethodFilter
;
import
org.springframework.boot.web.servlet.filter.OrderedHiddenHttpMethodFilter
;
import
org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter
;
import
org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter
;
import
org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter
;
import
org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ResourceLoaderAware
;
import
org.springframework.context.ResourceLoaderAware
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -130,6 +132,7 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver;
...
@@ -130,6 +132,7 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver;
* @author Eddú Meléndez
* @author Eddú Meléndez
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Kristine Jetzke
* @author Kristine Jetzke
* @author Bruce Brouwer
*/
*/
@Configuration
@Configuration
@ConditionalOnWebApplication
(
type
=
Type
.
SERVLET
)
@ConditionalOnWebApplication
(
type
=
Type
.
SERVLET
)
...
@@ -330,8 +333,11 @@ public class WebMvcAutoConfiguration {
...
@@ -330,8 +333,11 @@ public class WebMvcAutoConfiguration {
}
}
@Bean
@Bean
public
WelcomePageHandlerMapping
welcomePageHandlerMapping
()
{
public
WelcomePageHandlerMapping
welcomePageHandlerMapping
(
return
new
WelcomePageHandlerMapping
(
getWelcomePage
(),
ApplicationContext
applicationContext
)
{
return
new
WelcomePageHandlerMapping
(
new
TemplateAvailabilityProviders
(
applicationContext
),
applicationContext
,
getWelcomePage
(),
this
.
mvcProperties
.
getStaticPathPattern
());
this
.
mvcProperties
.
getStaticPathPattern
());
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WelcomePageHandlerMapping.java
View file @
cc855f44
...
@@ -24,6 +24,8 @@ import javax.servlet.http.HttpServletRequest;
...
@@ -24,6 +24,8 @@ import javax.servlet.http.HttpServletRequest;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.boot.autoconfigure.template.TemplateAvailabilityProviders
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.core.io.Resource
;
import
org.springframework.core.io.Resource
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
...
@@ -37,19 +39,37 @@ import org.springframework.web.servlet.mvc.ParameterizableViewController;
...
@@ -37,19 +39,37 @@ import org.springframework.web.servlet.mvc.ParameterizableViewController;
* static page is preferred.
* static page is preferred.
*
*
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Bruce Brouwer
*/
*/
final
class
WelcomePageHandlerMapping
extends
AbstractUrlHandlerMapping
{
final
class
WelcomePageHandlerMapping
extends
AbstractUrlHandlerMapping
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
WelcomePageHandlerMapping
.
class
);
private
static
final
Log
logger
=
LogFactory
.
getLog
(
WelcomePageHandlerMapping
.
class
);
WelcomePageHandlerMapping
(
Optional
<
Resource
>
welcomePage
,
String
staticPathPattern
)
{
WelcomePageHandlerMapping
(
TemplateAvailabilityProviders
templateAvailabilityProviders
,
if
(
welcomePage
.
isPresent
()
&&
"/**"
.
equals
(
staticPathPattern
))
{
ApplicationContext
applicationContext
,
Optional
<
Resource
>
welcomePage
,
logger
.
info
(
"Adding welcome page: "
+
welcomePage
.
get
());
String
staticPathPattern
)
{
ParameterizableViewController
controller
=
new
ParameterizableViewController
();
if
(
welcomeTemplateExists
(
templateAvailabilityProviders
,
applicationContext
))
{
controller
.
setViewName
(
"forward:index.html"
);
logger
.
info
(
"Adding welcome page template: index"
);
setRootHandler
(
controller
);
setRootViewName
(
"index"
);
setOrder
(
0
);
}
}
else
if
(
welcomePage
.
isPresent
()
&&
"/**"
.
equals
(
staticPathPattern
))
{
logger
.
info
(
"Adding welcome page: "
+
welcomePage
);
setRootViewName
(
"forward:index.html"
);
}
}
private
boolean
welcomeTemplateExists
(
TemplateAvailabilityProviders
templateAvailabilityProviders
,
ApplicationContext
applicationContext
)
{
return
templateAvailabilityProviders
.
getProvider
(
"index"
,
applicationContext
)
!=
null
;
}
private
void
setRootViewName
(
final
String
viewName
)
{
ParameterizableViewController
controller
=
new
ParameterizableViewController
();
controller
.
setViewName
(
viewName
);
setRootHandler
(
controller
);
setOrder
(
0
);
}
}
@Override
@Override
...
...
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