From 0bc3f446567b2539a459cd1a611271af290213ec Mon Sep 17 00:00:00 2001 From: chaos2418 <> Date: Sat, 8 Jan 2022 12:11:00 +0530 Subject: [PATCH] JAVA:8981: verify spring.mvc.pathmatch.matching-strategy property usage --- .../src/main/resources/application.properties | 2 +- spring-boot-modules/spring-boot-springdoc/pom.xml | 2 +- .../src/main/resources/application.properties | 5 +---- .../com/baeldung/spring/web/config/WebConfig.java | 2 +- .../src/main/resources/application.properties | 2 -- .../com/baeldung/spring/web/config/WebConfig.java | 5 ++--- .../src/main/resources/application.properties | 5 +---- ...ontrollerContentNegotiationIntegrationTest.java | 14 -------------- 8 files changed, 7 insertions(+), 30 deletions(-) diff --git a/spring-boot-modules/spring-boot-mvc/src/main/resources/application.properties b/spring-boot-modules/spring-boot-mvc/src/main/resources/application.properties index a24a95c8e7..aea61842d2 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-mvc/src/main/resources/application.properties @@ -1,2 +1,2 @@ spring.thymeleaf.view-names=thymeleaf/* -spring.mvc.pathmatch.matching-strategy=ant_path_matcher \ No newline at end of file +spring.mvc.pathmatch.matching-strategy=ant-path-matcher \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-springdoc/pom.xml b/spring-boot-modules/spring-boot-springdoc/pom.xml index b766aac3d4..d13efba450 100644 --- a/spring-boot-modules/spring-boot-springdoc/pom.xml +++ b/spring-boot-modules/spring-boot-springdoc/pom.xml @@ -206,7 +206,7 @@ - 1.5.2 + 1.6.4 1.5.6 1.6.0 ${project.build.directory}/generated-snippets diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/resources/application.properties b/spring-boot-modules/spring-boot-springdoc/src/main/resources/application.properties index 9e83617bad..733e716e76 100644 --- a/spring-boot-modules/spring-boot-springdoc/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-springdoc/src/main/resources/application.properties @@ -10,7 +10,4 @@ spring.datasource.url=jdbc:h2:mem:springdoc ## for com.baeldung.restdocopenapi ## springdoc.version=@springdoc.version@ -spring.jpa.hibernate.ddl-auto=none -###################################### - -spring.mvc.pathmatch.matching-strategy=ant_path_matcher \ No newline at end of file +spring.jpa.hibernate.ddl-auto=none \ No newline at end of file diff --git a/spring-web-modules/spring-mvc-basics-5/src/main/java/com/baeldung/spring/web/config/WebConfig.java b/spring-web-modules/spring-mvc-basics-5/src/main/java/com/baeldung/spring/web/config/WebConfig.java index f1a0e2d1a8..53865d02d5 100644 --- a/spring-web-modules/spring-mvc-basics-5/src/main/java/com/baeldung/spring/web/config/WebConfig.java +++ b/spring-web-modules/spring-mvc-basics-5/src/main/java/com/baeldung/spring/web/config/WebConfig.java @@ -33,7 +33,7 @@ public class WebConfig implements WebMvcConfigurer { /** Static resource locations */ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/resources/**/*") + registry.addResourceHandler("/resources/**") .addResourceLocations("/", "/resources/") .setCachePeriod(3600) .resourceChain(true) diff --git a/spring-web-modules/spring-mvc-basics-5/src/main/resources/application.properties b/spring-web-modules/spring-mvc-basics-5/src/main/resources/application.properties index c6d55580a3..935f91554b 100644 --- a/spring-web-modules/spring-mvc-basics-5/src/main/resources/application.properties +++ b/spring-web-modules/spring-mvc-basics-5/src/main/resources/application.properties @@ -1,3 +1 @@ server.servlet.context-path=/spring-mvc-basics - -spring.mvc.pathmatch.matching-strategy=ant-path-matcher diff --git a/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/spring/web/config/WebConfig.java b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/spring/web/config/WebConfig.java index e1987f8345..7b0d2ddf36 100644 --- a/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/spring/web/config/WebConfig.java +++ b/spring-web-modules/spring-mvc-basics/src/main/java/com/baeldung/spring/web/config/WebConfig.java @@ -53,7 +53,7 @@ public class WebConfig implements WebMvcConfigurer { /** Static resource locations including themes*/ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/resources/**/*") + registry.addResourceHandler("/resources/**") .addResourceLocations("/", "/resources/") .setCachePeriod(3600) .resourceChain(true) @@ -118,8 +118,7 @@ public class WebConfig implements WebMvcConfigurer { */ @Override public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) { - configurer.favorPathExtension(true) - .favorParameter(true) + configurer.favorParameter(true) .parameterName("mediaType") .ignoreAcceptHeader(false) .useRegisteredExtensionsOnly(false) diff --git a/spring-web-modules/spring-mvc-basics/src/main/resources/application.properties b/spring-web-modules/spring-mvc-basics/src/main/resources/application.properties index d25df689e3..a1ab6f1fe4 100644 --- a/spring-web-modules/spring-mvc-basics/src/main/resources/application.properties +++ b/spring-web-modules/spring-mvc-basics/src/main/resources/application.properties @@ -1,8 +1,5 @@ server.servlet.context-path=/spring-mvc-basics ### Content Negotiation (already defined programatically) -#spring.mvc.contentnegotiation.favor-path-extension=true #spring.mvc.contentnegotiation.favor-parameter=true -#spring.mvc.contentnegotiation.parameter-name=mediaType -spring.mvc.pathmatch.use-suffix-pattern=true -spring.mvc.pathmatch.matching-strategy=ant-path-matcher \ No newline at end of file +#spring.mvc.contentnegotiation.parameter-name=mediaType \ No newline at end of file diff --git a/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/EmployeeControllerContentNegotiationIntegrationTest.java b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/EmployeeControllerContentNegotiationIntegrationTest.java index 4ccba79f9c..0b9f26ab16 100644 --- a/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/EmployeeControllerContentNegotiationIntegrationTest.java +++ b/spring-web-modules/spring-mvc-basics/src/test/java/com/baeldung/web/controller/EmployeeControllerContentNegotiationIntegrationTest.java @@ -19,20 +19,6 @@ public class EmployeeControllerContentNegotiationIntegrationTest { @Autowired private MockMvc mockMvc; - @Test - public void whenEndpointUsingJsonSuffixCalled_thenJsonResponseObtained() throws Exception { - this.mockMvc.perform(get("/employee/1.json")) - .andExpect(status().isOk()) - .andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)); - } - - @Test - public void whenEndpointUsingXmlSuffixCalled_thenXmlResponseObtained() throws Exception { - this.mockMvc.perform(get("/employee/1.xml")) - .andExpect(status().isOk()) - .andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE)); - } - @Test public void whenEndpointUsingJsonParameterCalled_thenJsonResponseObtained() throws Exception { this.mockMvc.perform(get("/employee/1?mediaType=json"))