Merge pull request #11659 from chaos2418/JAVA-8981

JAVA:8981: verify spring.mvc.pathmatch.matching-strategy property usage
This commit is contained in:
kwoyke 2022-01-13 11:01:21 +01:00 committed by GitHub
commit 4000ebcf65
8 changed files with 7 additions and 30 deletions

View File

@ -1,2 +1,2 @@
spring.thymeleaf.view-names=thymeleaf/* spring.thymeleaf.view-names=thymeleaf/*
spring.mvc.pathmatch.matching-strategy=ant_path_matcher spring.mvc.pathmatch.matching-strategy=ant-path-matcher

View File

@ -206,7 +206,7 @@
</profiles> </profiles>
<properties> <properties>
<springdoc.version>1.5.2</springdoc.version> <springdoc.version>1.6.4</springdoc.version>
<asciidoctor-plugin.version>1.5.6</asciidoctor-plugin.version> <asciidoctor-plugin.version>1.5.6</asciidoctor-plugin.version>
<kotlin.version>1.6.0</kotlin.version> <kotlin.version>1.6.0</kotlin.version>
<snippetsDirectory>${project.build.directory}/generated-snippets</snippetsDirectory> <snippetsDirectory>${project.build.directory}/generated-snippets</snippetsDirectory>

View File

@ -10,7 +10,4 @@ spring.datasource.url=jdbc:h2:mem:springdoc
## for com.baeldung.restdocopenapi ## ## for com.baeldung.restdocopenapi ##
springdoc.version=@springdoc.version@ springdoc.version=@springdoc.version@
spring.jpa.hibernate.ddl-auto=none spring.jpa.hibernate.ddl-auto=none
######################################
spring.mvc.pathmatch.matching-strategy=ant_path_matcher

View File

@ -33,7 +33,7 @@ public class WebConfig implements WebMvcConfigurer {
/** Static resource locations */ /** Static resource locations */
@Override @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) { public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**/*") registry.addResourceHandler("/resources/**")
.addResourceLocations("/", "/resources/") .addResourceLocations("/", "/resources/")
.setCachePeriod(3600) .setCachePeriod(3600)
.resourceChain(true) .resourceChain(true)

View File

@ -1,3 +1 @@
server.servlet.context-path=/spring-mvc-basics server.servlet.context-path=/spring-mvc-basics
spring.mvc.pathmatch.matching-strategy=ant-path-matcher

View File

@ -53,7 +53,7 @@ public class WebConfig implements WebMvcConfigurer {
/** Static resource locations including themes*/ /** Static resource locations including themes*/
@Override @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) { public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**/*") registry.addResourceHandler("/resources/**")
.addResourceLocations("/", "/resources/") .addResourceLocations("/", "/resources/")
.setCachePeriod(3600) .setCachePeriod(3600)
.resourceChain(true) .resourceChain(true)
@ -118,8 +118,7 @@ public class WebConfig implements WebMvcConfigurer {
*/ */
@Override @Override
public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) { public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(true) configurer.favorParameter(true)
.favorParameter(true)
.parameterName("mediaType") .parameterName("mediaType")
.ignoreAcceptHeader(false) .ignoreAcceptHeader(false)
.useRegisteredExtensionsOnly(false) .useRegisteredExtensionsOnly(false)

View File

@ -1,8 +1,5 @@
server.servlet.context-path=/spring-mvc-basics server.servlet.context-path=/spring-mvc-basics
### Content Negotiation (already defined programatically) ### Content Negotiation (already defined programatically)
#spring.mvc.contentnegotiation.favor-path-extension=true
#spring.mvc.contentnegotiation.favor-parameter=true #spring.mvc.contentnegotiation.favor-parameter=true
#spring.mvc.contentnegotiation.parameter-name=mediaType #spring.mvc.contentnegotiation.parameter-name=mediaType
spring.mvc.pathmatch.use-suffix-pattern=true
spring.mvc.pathmatch.matching-strategy=ant-path-matcher

View File

@ -19,20 +19,6 @@ public class EmployeeControllerContentNegotiationIntegrationTest {
@Autowired @Autowired
private MockMvc mockMvc; 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 @Test
public void whenEndpointUsingJsonParameterCalled_thenJsonResponseObtained() throws Exception { public void whenEndpointUsingJsonParameterCalled_thenJsonResponseObtained() throws Exception {
this.mockMvc.perform(get("/employee/1?mediaType=json")) this.mockMvc.perform(get("/employee/1?mediaType=json"))