title: Make @ResponseBody-annotated Spring (Boot) MVC controller methods return UTF-8
body: <p>I'm building a Spring MVC service using Spring Boot and want to be able to return strings as plain text encoded in UTF-8. Following <a href="http://projects.spring.io/spring-boot/docs/docs/howto.html#toc_4" rel="nofollow noreferrer">this description</a>, I thought the only thing necessary should be to add the bean method</p>
  
  <pre><code>@Bean
  public HttpMessageConverter&lt;String&gt; responseBodyConverter() {
      StringHttpMessageConverter converter = new StringHttpMessageConverter();
      converter.setSupportedMediaTypes(Arrays.asList(new MediaType("text", "plain", Charset.forName("UTF-8"))));
      return converter;
  }
  </code></pre>
  
  <p>But the <code>root</code> method in</p>
  
  <pre><code>@Controller
  public class RootController {
  
      @RequestMapping(value="/"/*, produces="text/plain;charset=UTF-8"*/)
      @ResponseBody
      public String root() {
          return "æøå";
      }
  
  }
  </code></pre>
  
  <p>responds the string <code>æøå</code> in ISO-8859-1 instead of UTF-8, unless I uncomment the <code>produces</code> part, in which case it actually returns UTF-8. The message converter doesn't seems to have any effect here.</p>
  
  <p>Following <a href="https://spring.io/guides/gs/spring-boot/" rel="nofollow noreferrer">this approach</a> I confirm that the bean has actually been registered. Besides this bean, I also register an <code>EmbeddedServletContainerFactory</code> and <code>CharacterEncodingFilter</code> as described in <a href="https://stackoverflow.com/questions/20926329/non-ascii-symbols-in-path-variable-of-spring-mvc-application-on-embedded-tomcat/20926767">another question</a>, although I don't think that's relevant here.</p>
  
  <p>Can someone explain what the registered <code>HttpMessageConverter</code> actually does, and how to make <code>@ResponseBody</code>-annotated controller methods return UTF-8 without having to provide <code>produces</code> every time?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>As discussed in the comments, for the accepted answer to work, I had to upgrade the version of Spring Boot from <code>0.5.0.M6</code> to <code>0.5.0.BUILD-SNAPSHOT</code> and, to prevent outputting a junk header, call <code>converter.setWriteAcceptCharset(false)</code> on the <code>StringHttpMessageConverter</code>.</p>