Spring Handbook
  • Introduction
  • Web Applications
    • Creating REST API
    • Uploading File with REST API
    • Content Type Matching
  • Shell
    • Hello World Command
    • Securing Shell using Annotations
Powered by GitBook
On this page

Was this helpful?

  1. Web Applications

Content Type Matching

If we want to sent e.g. email as path variable, Spring Content matching algorithm will think ".com" from the email address is trying to say what should be the content type.

@GetMapping(value = "/user/{email}", produces = APPLICATION_JSON_UTF8_VALUE)

We can turn this off using the following config.

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class Config implements WebMvcConfigurer {

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.setUseSuffixPatternMatch(false);
    }

    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer.favorPathExtension(false);
    }
}
PreviousUploading File with REST APINextShell

Last updated 5 years ago

Was this helpful?