title: java.lang.IllegalArgumentException: Locale part "en-US,en;q=0.9" contains invalid characters]
body: <p>I got 400 bad request when I type, in Postman, the following URL http://localhost:8080/hello-world-internationalized
  <a href="https://i.stack.imgur.com/NZ6rQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NZ6rQ.png" alt="enter image description here" /></a>
  It's not the case if I specify the &quot;Accept-Language&quot; which is not required
  In fact I get the following Exception</p>
  <blockquote>
  <p>2020-07-05 12:02:43.617  WARN 7744 --- [nio-8080-exec-1] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.util.Locale'; nested exception is java.lang.IllegalArgumentException: Locale part &quot;en-US,en;q=0.9&quot; contains invalid characters]</p>
  </blockquote>
  <p>Bellow this is my controller</p>
  <pre><code>package com.in28minutes.rest.webservices.restfulwebservices.helloworld;
  
  import java.util.Locale;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.MessageSource;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestHeader;
  import org.springframework.web.bind.annotation.RestController;
  
  @RestController
  public class HelloWorldController {
      @Autowired
      private MessageSource messageSource;
  
  @GetMapping(path =&quot;/hello-world&quot;)
  public String helloWorld() {
      return &quot;Hello World!&quot;; 
  }
  
  @GetMapping(path =&quot;/hello-world-bean&quot;)
  public HelloWorldBean helloWorldBean() {
      return new HelloWorldBean(&quot;Hello World!&quot;); 
  }
  
  @GetMapping(path =&quot;/hello-world-bean/path-variable/{name}&quot;)
  public HelloWorldBean helloWorldPathVariable(@PathVariable String name) {
      return new HelloWorldBean(String.format(&quot;Hello, %s&quot;, name)); 
  }
  
  @GetMapping(path =&quot;/hello-world-internationalized&quot;)
  public String helloWorldInternationalized(@RequestHeader(name = &quot;Accept-Language&quot;, required = false) Locale locale) {
      return messageSource.getMessage(&quot;good.morning.message&quot;, null, locale); 
  }
  </code></pre>
  <p>}</p>
  <p>And</p>
  <pre><code>    package com.in28minutes.rest.webservices.restfulwebservices;
  
  import java.util.Locale;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.support.ResourceBundleMessageSource;
  import org.springframework.web.servlet.LocaleResolver;
  import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
  
  @SpringBootApplication
  public class RestfulWebServicesApplication {
      
  
      public static void main(String[] args) {
          SpringApplication.run(RestfulWebServicesApplication.class, args);
      }
      
      @Bean
      public LocaleResolver localeResolver() {
          AcceptHeaderLocaleResolver localeResolver= new AcceptHeaderLocaleResolver();
          localeResolver.setDefaultLocale(Locale.US);
          return localeResolver;
      }
      
      @Bean
      public ResourceBundleMessageSource messageSource() {
          ResourceBundleMessageSource messageSource= new ResourceBundleMessageSource();
          messageSource.setBasename(&quot;messages&quot;);
          return messageSource;
      }
      
  }
  </code></pre>
  <p>I created the project using Spring Intializr while picking spring boot 2.1.15, Java, Maven Project and Dependencies like Web, DevTools, JPA and H2.</p>