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
8dbaa4a4
Commit
8dbaa4a4
authored
Aug 23, 2013
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for web-jar resources
Include resource mapping for web-jar resources. Issue: #55752928
parent
fd2bfc0f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
0 deletions
+36
-0
WebMvcAutoConfiguration.java
...ework/boot/autoconfigure/web/WebMvcAutoConfiguration.java
+2
-0
WebMvcAutoConfigurationTests.java
.../boot/autoconfigure/web/WebMvcAutoConfigurationTests.java
+34
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java
View file @
8dbaa4a4
...
@@ -165,6 +165,8 @@ public class WebMvcAutoConfiguration {
...
@@ -165,6 +165,8 @@ public class WebMvcAutoConfiguration {
@Override
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
registry
.
addResourceHandler
(
"/webjars/**"
).
addResourceLocations
(
"classpath:/META-INF/resources/webjars/"
);
registry
.
addResourceHandler
(
"/**"
).
addResourceLocations
(
RESOURCE_LOCATIONS
);
registry
.
addResourceHandler
(
"/**"
).
addResourceLocations
(
RESOURCE_LOCATIONS
);
}
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java
View file @
8dbaa4a4
...
@@ -16,6 +16,9 @@
...
@@ -16,6 +16,9 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
web
;
package
org
.
springframework
.
boot
.
autoconfigure
.
web
;
import
java.lang.reflect.Field
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
...
@@ -31,12 +34,19 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory
...
@@ -31,12 +34,19 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory
import
org.springframework.boot.context.embedded.MockEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.MockEmbeddedServletContainerFactory
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.core.io.Resource
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.web.servlet.HandlerAdapter
;
import
org.springframework.web.servlet.HandlerAdapter
;
import
org.springframework.web.servlet.HandlerMapping
;
import
org.springframework.web.servlet.HandlerMapping
;
import
org.springframework.web.servlet.View
;
import
org.springframework.web.servlet.View
;
import
org.springframework.web.servlet.handler.SimpleUrlHandlerMapping
;
import
org.springframework.web.servlet.resource.ResourceHttpRequestHandler
;
import
org.springframework.web.servlet.view.AbstractView
;
import
org.springframework.web.servlet.view.AbstractView
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThat
;
/**
/**
* Tests for {@link WebMvcAutoConfiguration}.
* Tests for {@link WebMvcAutoConfiguration}.
...
@@ -76,6 +86,30 @@ public class WebMvcAutoConfigurationTests {
...
@@ -76,6 +86,30 @@ public class WebMvcAutoConfigurationTests {
assertEquals
(
6
,
this
.
context
.
getBeanNamesForType
(
HandlerMapping
.
class
).
length
);
assertEquals
(
6
,
this
.
context
.
getBeanNamesForType
(
HandlerMapping
.
class
).
length
);
}
}
@Test
@SuppressWarnings
(
"unchecked"
)
public
void
resourceHandlerMapping
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
this
.
context
.
register
(
Config
.
class
,
WebMvcAutoConfiguration
.
class
);
this
.
context
.
refresh
();
SimpleUrlHandlerMapping
mapping
=
(
SimpleUrlHandlerMapping
)
this
.
context
.
getBean
(
"resourceHandlerMapping"
);
Field
locationsField
=
ReflectionUtils
.
findField
(
ResourceHttpRequestHandler
.
class
,
"locations"
);
locationsField
.
setAccessible
(
true
);
Map
<
String
,
List
<
Resource
>>
mappingLocations
=
new
LinkedHashMap
<
String
,
List
<
Resource
>>();
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
mapping
.
getHandlerMap
().
entrySet
())
{
ResourceHttpRequestHandler
handler
=
(
ResourceHttpRequestHandler
)
entry
.
getValue
();
mappingLocations
.
put
(
entry
.
getKey
(),
(
List
<
Resource
>)
locationsField
.
get
(
handler
));
}
assertThat
(
mappingLocations
.
get
(
"/**"
).
size
(),
equalTo
(
5
));
assertThat
(
mappingLocations
.
get
(
"/webjars/**"
).
size
(),
equalTo
(
1
));
assertThat
(
mappingLocations
.
get
(
"/webjars/**"
).
get
(
0
),
equalTo
((
Resource
)
new
ClassPathResource
(
"/META-INF/resources/webjars/"
)));
}
@Configuration
@Configuration
protected
static
class
ViewConfig
{
protected
static
class
ViewConfig
{
...
...
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