Skip to content

Commit 859b266

Browse files
author
Phillip Webb
committed
Remove '/resources/**' mapping and default servlet
Remove '/resources/**' mapping since it can cause problems with the '/**' when the developer defines their own 'resources' sub-folder. Also remove default servlet config since the resources mapping renders it redundant. Issue: #55494446
1 parent e55fc94 commit 859b266

File tree

6 files changed

+13
-22
lines changed

6 files changed

+13
-22
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java

-9
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import org.springframework.web.filter.HiddenHttpMethodFilter;
4949
import org.springframework.web.servlet.DispatcherServlet;
5050
import org.springframework.web.servlet.View;
51-
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
5251
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
5352
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
5453
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
@@ -145,12 +144,6 @@ public ContentNegotiatingViewResolver viewResolver(BeanFactory beanFactory) {
145144
return resolver;
146145
}
147146

148-
@Override
149-
public void configureDefaultServletHandling(
150-
DefaultServletHandlerConfigurer configurer) {
151-
configurer.enable();
152-
}
153-
154147
@Override
155148
public void addFormatters(FormatterRegistry registry) {
156149
for (Converter<?, ?> converter : getBeansOfType(Converter.class)) {
@@ -172,8 +165,6 @@ private <T> Collection<T> getBeansOfType(Class<T> type) {
172165

173166
@Override
174167
public void addResourceHandlers(ResourceHandlerRegistry registry) {
175-
registry.addResourceHandler("/resources/**").addResourceLocations(
176-
RESOURCE_LOCATIONS);
177168
registry.addResourceHandler("/**").addResourceLocations(RESOURCE_LOCATIONS);
178169
}
179170

spring-boot-samples/spring-boot-sample-actuator-ui/src/main/resources/templates/error.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<html xmlns:th="http://www.thymeleaf.org">
33
<head>
44
<title>Error</title>
5-
<link rel="stylesheet" th:href="@{/resources/css/bootstrap.min.css}"
6-
href="../../resources/css/bootstrap.min.css" />
5+
<link rel="stylesheet" th:href="@{/css/bootstrap.min.css}"
6+
href="../../css/bootstrap.min.css" />
77
</head>
88
<body>
99
<div class="container">
@@ -28,4 +28,4 @@ <h1 th:text="${title}">Title</h1>
2828
</div>
2929
</div>
3030
</body>
31-
</html>
31+
</html>

spring-boot-samples/spring-boot-sample-actuator-ui/src/main/resources/templates/home.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<html xmlns:th="http://www.thymeleaf.org">
33
<head>
44
<title th:text="${title}">Title</title>
5-
<link rel="stylesheet" th:href="@{/resources/css/bootstrap.min.css}"
6-
href="../../resources/css/bootstrap.min.css" />
5+
<link rel="stylesheet" th:href="@{/css/bootstrap.min.css}"
6+
href="../../css/bootstrap.min.css" />
77
</head>
88
<body>
99
<div class="container">
@@ -22,4 +22,4 @@ <h1 th:text="${title}">Title</h1>
2222
2012 2:17:16 PM CDT</div>
2323
</div>
2424
</body>
25-
</html>
25+
</html>

spring-boot-samples/spring-boot-sample-web-static/src/test/java/org/springframework/boot/sample/ui/SampleWebStaticApplicationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/**
2525
* Basic integration tests for demo application.
26-
*
26+
*
2727
* @author Dave Syer
2828
*/
2929
public class SampleWebStaticApplicationTests {
@@ -63,7 +63,7 @@ public void testHome() throws Exception {
6363
@Test
6464
public void testCss() throws Exception {
6565
ResponseEntity<String> entity = getRestTemplate().getForEntity(
66-
"http://localhost:8080/resources/css/bootstrap.min.css", String.class);
66+
"http://localhost:8080/css/bootstrap.min.css", String.class);
6767
assertEquals(HttpStatus.OK, entity.getStatusCode());
6868
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
6969
assertEquals("Wrong content type:\n" + entity.getHeaders().getContentType(),

spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/layout.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<head>
44
<title>Layout</title>
55
<link rel="stylesheet"
6-
th:href="@{/resources/css/bootstrap.min.css}"
7-
href="../../resources/css/bootstrap.min.css"/>
6+
th:href="@{/css/bootstrap.min.css}"
7+
href="../../css/bootstrap.min.css"/>
88
</head>
99
<body>
1010
<div class="container">
@@ -29,4 +29,4 @@ <h1 layout:fragment="header">Layout</h1>
2929
</div>
3030
</div>
3131
</body>
32-
</html>
32+
</html>

spring-boot-samples/spring-boot-sample-web-ui/src/test/java/org/springframework/boot/sample/ui/SampleWebUiApplicationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
/**
2828
* Basic integration tests for demo application.
29-
*
29+
*
3030
* @author Dave Syer
3131
*/
3232
public class SampleWebUiApplicationTests {
@@ -78,7 +78,7 @@ public void testCreate() throws Exception {
7878
@Test
7979
public void testCss() throws Exception {
8080
ResponseEntity<String> entity = getRestTemplate().getForEntity(
81-
"http://localhost:8080/resources/css/bootstrap.min.css", String.class);
81+
"http://localhost:8080/css/bootstrap.min.css", String.class);
8282
assertEquals(HttpStatus.OK, entity.getStatusCode());
8383
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
8484
}

0 commit comments

Comments
 (0)