JAVA:8981: verify spring.mvc.pathmatch.matching-strategy property usage

This commit is contained in:
chaos2418
2022-01-08 12:11:00 +05:30
parent b42e037d1d
commit 5d12326819
8 changed files with 7 additions and 30 deletions

View File

@@ -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)

View File

@@ -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
#spring.mvc.contentnegotiation.parameter-name=mediaType

View File

@@ -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"))