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
cb98ee25
Commit
cb98ee25
authored
Jun 17, 2015
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
See gh-2900
parent
8b9c3808
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
121 deletions
+48
-121
WebMvcProperties.java
...ingframework/boot/autoconfigure/web/WebMvcProperties.java
+2
-2
WebMvcAutoConfigurationTests.java
.../boot/autoconfigure/web/WebMvcAutoConfigurationTests.java
+45
-118
appendix-application-properties.adoc
...cs/src/main/asciidoc/appendix-application-properties.adoc
+1
-1
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcProperties.java
View file @
cb98ee25
/*
* Copyright 2012-201
4
the original author or authors.
* Copyright 2012-201
5
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -92,7 +92,7 @@ public class WebMvcProperties {
public
static
class
Async
{
/**
*
The a
mount of time (in milliseconds) before asynchronous request handling times
*
A
mount of time (in milliseconds) before asynchronous request handling times
* out. If this value is not set, the default timeout of the underlying
* implementation is used, e.g. 10 seconds on Tomcat with Servlet 3.
*/
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java
View file @
cb98ee25
...
...
@@ -17,6 +17,8 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
web
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
...
...
@@ -79,6 +81,7 @@ import static org.junit.Assert.assertThat;
* @author Phillip Webb
* @author Dave Syer
* @author Andy Wilkinson
* @author Stephane Nicoll
*/
public
class
WebMvcAutoConfigurationTests
{
...
...
@@ -98,11 +101,7 @@ public class WebMvcAutoConfigurationTests {
@Test
public
void
handerAdaptersCreated
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
this
.
context
.
register
(
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
();
assertEquals
(
3
,
this
.
context
.
getBeanNamesForType
(
HandlerAdapter
.
class
).
length
);
assertFalse
(
this
.
context
.
getBean
(
RequestMappingHandlerAdapter
.
class
)
.
getMessageConverters
().
isEmpty
());
...
...
@@ -113,21 +112,13 @@ public class WebMvcAutoConfigurationTests {
@Test
public
void
handerMappingsCreated
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
this
.
context
.
register
(
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
();
assertEquals
(
6
,
this
.
context
.
getBeanNamesForType
(
HandlerMapping
.
class
).
length
);
}
@Test
public
void
resourceHandlerMapping
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
this
.
context
.
register
(
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
();
Map
<
String
,
List
<
Resource
>>
mappingLocations
=
getResourceMappingLocations
();
assertThat
(
mappingLocations
.
get
(
"/**"
).
size
(),
equalTo
(
5
));
assertThat
(
mappingLocations
.
get
(
"/webjars/**"
).
size
(),
equalTo
(
1
));
...
...
@@ -137,11 +128,7 @@ public class WebMvcAutoConfigurationTests {
@Test
public
void
resourceHandlerMappingOverrideWebjars
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
this
.
context
.
register
(
WebJars
.
class
,
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
(
WebJars
.
class
);
Map
<
String
,
List
<
Resource
>>
mappingLocations
=
getResourceMappingLocations
();
assertThat
(
mappingLocations
.
get
(
"/webjars/**"
).
size
(),
equalTo
(
1
));
assertThat
(
mappingLocations
.
get
(
"/webjars/**"
).
get
(
0
),
...
...
@@ -149,13 +136,8 @@ public class WebMvcAutoConfigurationTests {
}
@Test
public
void
resourceHandlerMappingOverrideAll
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
this
.
context
.
register
(
AllResources
.
class
,
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
public
void
resourceHandlerMappingOverrideAll
()
throws
Exception
{
load
(
AllResources
.
class
);
Map
<
String
,
List
<
Resource
>>
mappingLocations
=
getResourceMappingLocations
();
assertThat
(
mappingLocations
.
get
(
"/**"
).
size
(),
equalTo
(
1
));
assertThat
(
mappingLocations
.
get
(
"/**"
).
get
(
0
),
...
...
@@ -164,39 +146,22 @@ public class WebMvcAutoConfigurationTests {
@Test
public
void
resourceHandlerMappingDisabled
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.resources.add-mappings:false"
);
this
.
context
.
register
(
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
(
"spring.resources.add-mappings:false"
);
Map
<
String
,
List
<
Resource
>>
mappingLocations
=
getResourceMappingLocations
();
assertThat
(
mappingLocations
.
size
(),
equalTo
(
0
));
}
@Test
public
void
noLocaleResolver
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
this
.
context
.
register
(
AllResources
.
class
,
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
(
AllResources
.
class
);
this
.
thrown
.
expect
(
NoSuchBeanDefinitionException
.
class
);
this
.
context
.
getBean
(
LocaleResolver
.
class
);
}
@Test
public
void
overrideLocale
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
// set fixed locale
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.mvc.locale:en_UK"
);
this
.
context
.
register
(
AllResources
.
class
,
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
(
AllResources
.
class
,
"spring.mvc.locale:en_UK"
);
// mock request and set user preferred locale
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
request
.
addPreferredLocale
(
StringUtils
.
parseLocaleString
(
"nl_NL"
));
...
...
@@ -209,12 +174,7 @@ public class WebMvcAutoConfigurationTests {
@Test
public
void
noDateFormat
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
this
.
context
.
register
(
AllResources
.
class
,
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
(
AllResources
.
class
);
FormattingConversionService
cs
=
this
.
context
.
getBean
(
FormattingConversionService
.
class
);
Date
date
=
new
DateTime
(
1988
,
6
,
25
,
20
,
30
).
toDate
();
...
...
@@ -224,15 +184,7 @@ public class WebMvcAutoConfigurationTests {
@Test
public
void
overrideDateFormat
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
// set fixed date format
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.mvc.dateFormat:dd*MM*yyyy"
);
this
.
context
.
register
(
AllResources
.
class
,
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
(
AllResources
.
class
,
"spring.mvc.dateFormat:dd*MM*yyyy"
);
FormattingConversionService
cs
=
this
.
context
.
getBean
(
FormattingConversionService
.
class
);
Date
date
=
new
DateTime
(
1988
,
6
,
25
,
20
,
30
).
toDate
();
...
...
@@ -241,26 +193,14 @@ public class WebMvcAutoConfigurationTests {
@Test
public
void
noMessageCodesResolver
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
this
.
context
.
register
(
AllResources
.
class
,
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
(
AllResources
.
class
);
assertNull
(
this
.
context
.
getBean
(
WebMvcAutoConfigurationAdapter
.
class
)
.
getMessageCodesResolver
());
}
@Test
public
void
overrideMessageCodesFormat
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.mvc.messageCodesResolverFormat:POSTFIX_ERROR_CODE"
);
this
.
context
.
register
(
AllResources
.
class
,
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
(
AllResources
.
class
,
"spring.mvc.messageCodesResolverFormat:POSTFIX_ERROR_CODE"
);
assertNotNull
(
this
.
context
.
getBean
(
WebMvcAutoConfigurationAdapter
.
class
)
.
getMessageCodesResolver
());
}
...
...
@@ -300,11 +240,7 @@ public class WebMvcAutoConfigurationTests {
@Test
public
void
ignoreDefaultModelOnRedirectIsTrue
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
this
.
context
.
register
(
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
();
RequestMappingHandlerAdapter
adapter
=
this
.
context
.
getBean
(
RequestMappingHandlerAdapter
.
class
);
assertEquals
(
true
,
...
...
@@ -328,23 +264,13 @@ public class WebMvcAutoConfigurationTests {
@Test
public
void
customViewResolver
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
this
.
context
.
register
(
Config
.
class
,
CustomViewResolver
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
(
CustomViewResolver
.
class
);
assertThat
(
this
.
context
.
getBean
(
"viewResolver"
),
instanceOf
(
MyViewResolver
.
class
));
}
@Test
public
void
customContentNegotiatingViewResolver
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
this
.
context
.
register
(
Config
.
class
,
CustomContentNegotiatingViewResolver
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
(
CustomContentNegotiatingViewResolver
.
class
);
Map
<
String
,
ContentNegotiatingViewResolver
>
beans
=
this
.
context
.
getBeansOfType
(
ContentNegotiatingViewResolver
.
class
);
assertThat
(
beans
.
size
(),
equalTo
(
1
));
...
...
@@ -353,11 +279,7 @@ public class WebMvcAutoConfigurationTests {
@Test
public
void
faviconMapping
()
throws
IllegalAccessException
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
this
.
context
.
register
(
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
();
assertThat
(
this
.
context
.
getBeansOfType
(
ResourceHttpRequestHandler
.
class
).
get
(
"faviconRequestHandler"
),
is
(
notNullValue
()));
...
...
@@ -370,13 +292,7 @@ public class WebMvcAutoConfigurationTests {
@Test
public
void
faviconMappingDisabled
()
throws
IllegalAccessException
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
this
.
context
.
register
(
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.mvc.favicon.enabled:false"
);
this
.
context
.
refresh
();
load
(
"spring.mvc.favicon.enabled:false"
);
assertThat
(
this
.
context
.
getBeansOfType
(
ResourceHttpRequestHandler
.
class
).
get
(
"faviconRequestHandler"
),
is
(
nullValue
()));
...
...
@@ -387,11 +303,7 @@ public class WebMvcAutoConfigurationTests {
@Test
public
void
defaultAsyncRequestTimeout
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
this
.
context
.
register
(
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
();
RequestMappingHandlerAdapter
adapter
=
this
.
context
.
getBean
(
RequestMappingHandlerAdapter
.
class
);
assertNull
(
ReflectionTestUtils
.
getField
(
adapter
,
"asyncRequestTimeout"
));
...
...
@@ -399,19 +311,34 @@ public class WebMvcAutoConfigurationTests {
@Test
public
void
customAsyncRequestTimeout
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.mvc.async.request-timeout:123456"
);
this
.
context
.
register
(
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
(
"spring.mvc.async.request-timeout:123456"
);
RequestMappingHandlerAdapter
adapter
=
this
.
context
.
getBean
(
RequestMappingHandlerAdapter
.
class
);
Object
actual
=
ReflectionTestUtils
.
getField
(
adapter
,
"asyncRequestTimeout"
);
assertEquals
(
123456L
,
actual
);
}
@SuppressWarnings
(
"unchecked"
)
private
void
load
(
Class
<?>
config
,
String
...
environment
)
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
environment
);
List
<
Class
<?>>
configClasses
=
new
ArrayList
<
Class
<?>>();
if
(
config
!=
null
)
{
configClasses
.
add
(
config
);
}
configClasses
.
addAll
(
Arrays
.
asList
(
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
));
this
.
context
.
register
(
configClasses
.
toArray
(
new
Class
<?>[
configClasses
.
size
()]));
this
.
context
.
refresh
();
}
private
void
load
(
String
...
environment
)
{
load
(
null
,
environment
);
}
@Configuration
protected
static
class
ViewConfig
{
...
...
spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
View file @
cb98ee25
...
...
@@ -121,7 +121,7 @@ content into your application; rather pick only the properties that you need.
spring.mvc.favicon.enabled=true
spring.mvc.message-codes-resolver-format= # PREFIX_ERROR_CODE / POSTFIX_ERROR_CODE
spring.mvc.ignore-default-model-on-redirect=true # if the the content of the "default" model should be ignored redirects
spring.mvc.async.request-timeout= # async timeout in milliseconds
spring.mvc.async.request-timeout= # async
request
timeout in milliseconds
spring.view.prefix= # MVC view prefix
spring.view.suffix= # ... and suffix
...
...
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