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
772cc851
Commit
772cc851
authored
Jul 29, 2013
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish WebMvcAutoConfiguration resource locations
parent
728829ba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
17 deletions
+37
-17
WebMvcAutoConfiguration.java
...ework/boot/autoconfigure/web/WebMvcAutoConfiguration.java
+37
-17
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java
View file @
772cc851
...
@@ -70,6 +70,31 @@ import org.springframework.web.servlet.view.ContentNegotiatingViewResolver;
...
@@ -70,6 +70,31 @@ import org.springframework.web.servlet.view.ContentNegotiatingViewResolver;
@AutoConfigureAfter
(
EmbeddedServletContainerAutoConfiguration
.
class
)
@AutoConfigureAfter
(
EmbeddedServletContainerAutoConfiguration
.
class
)
public
class
WebMvcAutoConfiguration
{
public
class
WebMvcAutoConfiguration
{
private
static
final
String
[]
SERVLET_RESOURCE_LOCATIONS
=
{
"/"
};
private
static
final
String
[]
CLASSPATH_RESOURCE_LOCATIONS
=
{
"classpath:/META-INF/resources/"
,
"classpath:/resources/"
,
"classpath:/static/"
,
"classpath:/public/"
};
private
static
final
String
[]
RESOURCE_LOCATIONS
;
static
{
RESOURCE_LOCATIONS
=
new
String
[
CLASSPATH_RESOURCE_LOCATIONS
.
length
+
SERVLET_RESOURCE_LOCATIONS
.
length
];
System
.
arraycopy
(
SERVLET_RESOURCE_LOCATIONS
,
0
,
RESOURCE_LOCATIONS
,
0
,
SERVLET_RESOURCE_LOCATIONS
.
length
);
System
.
arraycopy
(
CLASSPATH_RESOURCE_LOCATIONS
,
0
,
RESOURCE_LOCATIONS
,
SERVLET_RESOURCE_LOCATIONS
.
length
,
CLASSPATH_RESOURCE_LOCATIONS
.
length
);
}
private
static
final
String
[]
STATIC_INDEX_HTML_RESOURCES
;
static
{
STATIC_INDEX_HTML_RESOURCES
=
new
String
[
CLASSPATH_RESOURCE_LOCATIONS
.
length
];
for
(
int
i
=
0
;
i
<
STATIC_INDEX_HTML_RESOURCES
.
length
;
i
++)
{
STATIC_INDEX_HTML_RESOURCES
[
i
]
=
CLASSPATH_RESOURCE_LOCATIONS
[
i
]
+
"index.html"
;
}
}
// Defined as a nested config to ensure WebMvcConfigurerAdapter it not read when not
// Defined as a nested config to ensure WebMvcConfigurerAdapter it not read when not
// on the classpath
// on the classpath
@EnableWebMvc
@EnableWebMvc
...
@@ -125,27 +150,22 @@ public class WebMvcAutoConfiguration {
...
@@ -125,27 +150,22 @@ public class WebMvcAutoConfiguration {
@Override
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
registry
.
addResourceHandler
(
"/resources/**"
).
addResourceLocations
(
"/"
,
registry
.
addResourceHandler
(
"/resources/**"
).
addResourceLocations
(
"classpath:/META-INF/resources/"
,
"classpath:/resources/"
,
RESOURCE_LOCATIONS
);
"classpath:/public/"
,
"classpath:/static/"
);
registry
.
addResourceHandler
(
"/**"
).
addResourceLocations
(
RESOURCE_LOCATIONS
);
registry
.
addResourceHandler
(
"/**"
).
addResourceLocations
(
"/"
,
"classpath:/META-INF/resources/"
,
"classpath:/resources/"
,
"classpath:/static/"
,
"classpath:/public/"
);
}
}
// Special case for static home page
@Override
@Override
public
void
addViewControllers
(
ViewControllerRegistry
registry
)
{
public
void
addViewControllers
(
ViewControllerRegistry
registry
)
{
if
(
this
.
resourceLoader
.
getResource
(
"classpath:/static/index.html"
).
exists
())
{
addStaticIndexHtmlViewControllers
(
registry
);
registry
.
addViewController
(
"/"
).
setViewName
(
"/index.html"
);
}
}
else
if
(
this
.
resourceLoader
.
getResource
(
"classpath:/public/index.html"
)
private
void
addStaticIndexHtmlViewControllers
(
ViewControllerRegistry
registry
)
{
.
exists
())
{
for
(
String
resource
:
STATIC_INDEX_HTML_RESOURCES
)
{
registry
.
addViewController
(
"/"
).
setViewName
(
"/index.html"
);
if
(
this
.
resourceLoader
.
getResource
(
resource
).
exists
())
{
}
registry
.
addViewController
(
"/"
).
setViewName
(
"/index.html"
);
else
if
(
this
.
resourceLoader
.
getResource
(
"classpath:/resources/index.html"
)
return
;
.
exists
())
{
}
registry
.
addViewController
(
"/"
).
setViewName
(
"/index.html"
);
}
}
}
}
...
...
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