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
6a32955c
Commit
6a32955c
authored
Nov 12, 2015
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4448 from eddumelendez/gh-4444
* pr/4448: Add `spring.mvc.static-path-pattern` property
parents
854dadc6
066533de
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
2 deletions
+28
-2
WebMvcAutoConfiguration.java
...ework/boot/autoconfigure/web/WebMvcAutoConfiguration.java
+4
-2
WebMvcProperties.java
...ingframework/boot/autoconfigure/web/WebMvcProperties.java
+14
-0
WebMvcAutoConfigurationTests.java
.../boot/autoconfigure/web/WebMvcAutoConfigurationTests.java
+9
-0
appendix-application-properties.adoc
...cs/src/main/asciidoc/appendix-application-properties.adoc
+1
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java
View file @
6a32955c
...
@@ -98,6 +98,7 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver;
...
@@ -98,6 +98,7 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver;
* @author Dave Syer
* @author Dave Syer
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Sébastien Deleuze
* @author Sébastien Deleuze
* @author Eddú Meléndez
*/
*/
@Configuration
@Configuration
@ConditionalOnWebApplication
@ConditionalOnWebApplication
...
@@ -256,8 +257,9 @@ public class WebMvcAutoConfiguration {
...
@@ -256,8 +257,9 @@ public class WebMvcAutoConfiguration {
.
addResourceLocations
(
"classpath:/META-INF/resources/webjars/"
)
.
addResourceLocations
(
"classpath:/META-INF/resources/webjars/"
)
.
setCachePeriod
(
cachePeriod
));
.
setCachePeriod
(
cachePeriod
));
}
}
if
(!
registry
.
hasMappingForPattern
(
"/**"
))
{
String
staticPathPattern
=
this
.
mvcProperties
.
getStaticPathPattern
();
registerResourceChain
(
registry
.
addResourceHandler
(
"/**"
)
if
(!
registry
.
hasMappingForPattern
(
staticPathPattern
))
{
registerResourceChain
(
registry
.
addResourceHandler
(
staticPathPattern
)
.
addResourceLocations
(
.
addResourceLocations
(
this
.
resourceProperties
.
getStaticLocations
())
this
.
resourceProperties
.
getStaticLocations
())
.
setCachePeriod
(
cachePeriod
));
.
setCachePeriod
(
cachePeriod
));
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcProperties.java
View file @
6a32955c
...
@@ -31,6 +31,7 @@ import org.springframework.validation.DefaultMessageCodesResolver;
...
@@ -31,6 +31,7 @@ import org.springframework.validation.DefaultMessageCodesResolver;
* @author Phillip Webb
* @author Phillip Webb
* @author Sébastien Deleuze
* @author Sébastien Deleuze
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Eddú Meléndez
* @since 1.1
* @since 1.1
*/
*/
@ConfigurationProperties
(
"spring.mvc"
)
@ConfigurationProperties
(
"spring.mvc"
)
...
@@ -77,6 +78,11 @@ public class WebMvcProperties {
...
@@ -77,6 +78,11 @@ public class WebMvcProperties {
*/
*/
private
Map
<
String
,
MediaType
>
mediaTypes
=
new
LinkedHashMap
<
String
,
MediaType
>();
private
Map
<
String
,
MediaType
>
mediaTypes
=
new
LinkedHashMap
<
String
,
MediaType
>();
/**
* Path that pattern used for static resources.
*/
private
String
staticPathPattern
=
"/**"
;
private
final
Async
async
=
new
Async
();
private
final
Async
async
=
new
Async
();
private
final
View
view
=
new
View
();
private
final
View
view
=
new
View
();
...
@@ -147,6 +153,14 @@ public class WebMvcProperties {
...
@@ -147,6 +153,14 @@ public class WebMvcProperties {
this
.
dispatchTraceRequest
=
dispatchTraceRequest
;
this
.
dispatchTraceRequest
=
dispatchTraceRequest
;
}
}
public
String
getStaticPathPattern
()
{
return
this
.
staticPathPattern
;
}
public
void
setStaticPathPattern
(
String
staticPathPattern
)
{
this
.
staticPathPattern
=
staticPathPattern
;
}
public
Async
getAsync
()
{
public
Async
getAsync
()
{
return
this
.
async
;
return
this
.
async
;
}
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java
View file @
6a32955c
...
@@ -101,6 +101,7 @@ import static org.junit.Assert.assertTrue;
...
@@ -101,6 +101,7 @@ import static org.junit.Assert.assertTrue;
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Brian Clozel
* @author Brian Clozel
* @author Eddú Meléndez
*/
*/
public
class
WebMvcAutoConfigurationTests
{
public
class
WebMvcAutoConfigurationTests
{
...
@@ -149,6 +150,14 @@ public class WebMvcAutoConfigurationTests {
...
@@ -149,6 +150,14 @@ public class WebMvcAutoConfigurationTests {
assertThat
(
getResourceTransformers
(
"/**"
).
size
(),
equalTo
(
0
));
assertThat
(
getResourceTransformers
(
"/**"
).
size
(),
equalTo
(
0
));
}
}
@Test
public
void
customResourceHandlerMapping
()
throws
Exception
{
load
(
"spring.mvc.static-path-pattern:/static/**"
);
Map
<
String
,
List
<
Resource
>>
mappingLocations
=
getResourceMappingLocations
();
assertThat
(
mappingLocations
.
get
(
"/static/**"
).
size
(),
equalTo
(
5
));
assertThat
(
getResourceResolvers
(
"/static/**"
).
size
(),
equalTo
(
1
));
}
@Test
@Test
public
void
resourceHandlerMappingOverrideWebjars
()
throws
Exception
{
public
void
resourceHandlerMappingOverrideWebjars
()
throws
Exception
{
load
(
WebJars
.
class
);
load
(
WebJars
.
class
);
...
...
spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
View file @
6a32955c
...
@@ -310,6 +310,7 @@ content into your application; rather pick only the properties that you need.
...
@@ -310,6 +310,7 @@ content into your application; rather pick only the properties that you need.
spring.mvc.locale= # Locale to use.
spring.mvc.locale= # Locale to use.
spring.mvc.media-types.*= # Maps file extensions to media types for content negotiation.
spring.mvc.media-types.*= # Maps file extensions to media types for content negotiation.
spring.mvc.message-codes-resolver-format= # Formatting strategy for message codes. For instance `PREFIX_ERROR_CODE`.
spring.mvc.message-codes-resolver-format= # Formatting strategy for message codes. For instance `PREFIX_ERROR_CODE`.
spring.mvc.static-path-pattern=/** # Path that pattern used for static resources.
spring.mvc.throw-exception-if-no-handler-found=false # If a "NoHandlerFoundException" should be thrown if no Handler was found to process a request.
spring.mvc.throw-exception-if-no-handler-found=false # If a "NoHandlerFoundException" should be thrown if no Handler was found to process a request.
spring.mvc.view.prefix= # Spring MVC view prefix.
spring.mvc.view.prefix= # Spring MVC view prefix.
spring.mvc.view.suffix= # Spring MVC view suffix.
spring.mvc.view.suffix= # Spring MVC view 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