title: How to set UTF-8 character encoding in Spring boot?
body: <p>I use spring-boot in my project, and I run this jar file which is built by spring-boot as a service on Centos. When I run this service: </p>
  
  <blockquote>
    <p>service myApp start</p>
  </blockquote>
  
  <p>I always get the below error messages:</p>
  
  <pre><code>2016-08-26 09:11:02.002 ERROR 31900 --- [           main] o.s.b.c.FileEncodingApplicationListener  : System property 'file.encoding' is currently 'ANSI_X3.4-1968'. It should be 'UTF-8' (as defined in 'spring.mandatoryFileEncoding').
  2016-08-26 09:11:02.018 ERROR 31900 --- [           main] o.s.b.c.FileEncodingApplicationListener  : Environment variable LANG is 'null'. You could use a locale setting that matches encoding='UTF-8'.
  2016-08-26 09:11:02.018 ERROR 31900 --- [           main] o.s.b.c.FileEncodingApplicationListener  : Environment variable LC_ALL is 'null'. You could use a locale setting that matches encoding='UTF-8'.
  2016-08-26 09:11:02.031 ERROR 31900 --- [           main] o.s.boot.SpringApplication               : Application startup failed
  java.lang.IllegalStateException: The Java Virtual Machine has not been configured to use the desired default character encoding (UTF-8).
      at org.springframework.boot.context.FileEncodingApplicationListener.onApplicationEvent(FileEncodingApplicationListener.java:74) ~[spring-boot-1.3.7.RELEASE.jar!/:1.3.7.RELEASE]
  </code></pre>
  
  <p>If I run this jar file directly, then this application runs properly.</p>
  
  <blockquote>
    <p>java -jar target/myApp-1.0.jar</p>
  </blockquote>
  
  <pre><code> .   ____          _            __ _ _
   /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
  ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
   \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
    '  |____| .__|_| |_|_| |_\__, | / / / /
   =========|_|==============|___/=/_/_/_/
   :: Spring Boot ::        (v1.3.7.RELEASE)
  
  ......
  
  2016-08-26 09:54:34.954 DEBUG 32035 --- [           main] o.s.w.s.resource.ResourceUrlProvider     : Found resource handler mapping: URL pattern="/**", locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@1817d444]
  2016-08-26 09:54:35.051  INFO 32035 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8000 (http)
  2016-08-26 09:54:35.053 DEBUG 32035 --- [           main] o.s.w.c.s.StandardServletEnvironment     : Adding [server.ports] PropertySource with highest search precedence
  2016-08-26 09:54:35.061  INFO 32035 --- [           main] co.nz.myApplication           : Started myApplication in 12.339 seconds (JVM running for 13.183)
  </code></pre>
  
  <p>This is pom.xml:</p>
  
  <pre><code>&lt;project&gt;
  ....
  
   &lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.3.7.RELEASE&lt;/version&gt;
      &lt;relativePath/&gt;
   &lt;/parent&gt;
  
   &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;java.version&gt;1.8&lt;/java.version&gt;
   &lt;/properties&gt;
   ....
  
   &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;configuration&gt;
                  &lt;executable&gt;true&lt;/executable&gt;
                  &lt;jvmArguments&gt;-Dfile.encoding=UTF8 -Dspring.profiles.active="production"&lt;/jvmArguments&gt;
              &lt;/configuration&gt;
              &lt;dependencies&gt;
                  &lt;dependency&gt;
                      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                      &lt;artifactId&gt;springloaded&lt;/artifactId&gt;
                      &lt;version&gt;1.2.5.RELEASE&lt;/version&gt;
                  &lt;/dependency&gt;
              &lt;/dependencies&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
   &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>application.properties:</p>
  
  <pre><code>....
  spring.mandatory-file-encoding=UTF-8
  spring.http.encoding.charset=UTF-8
  spring.http.encoding.enabled=true
  ....
  </code></pre>
  
  <p>locale setting on Centos:</p>
  
  <pre><code>$ locale
  
  LANG=en_US.UTF-8
  LC_CTYPE="en_US.UTF-8"
  LC_NUMERIC="en_US.UTF-8"
  LC_TIME="en_US.UTF-8"
  LC_COLLATE="en_US.UTF-8"
  LC_MONETARY="en_US.UTF-8"
  LC_MESSAGES="en_US.UTF-8"
  LC_PAPER="en_US.UTF-8"
  LC_NAME="en_US.UTF-8"
  LC_ADDRESS="en_US.UTF-8"
  LC_TELEPHONE="en_US.UTF-8"
  LC_MEASUREMENT="en_US.UTF-8"
  LC_IDENTIFICATION="en_US.UTF-8"
  LC_ALL=en_US.UTF-8
  </code></pre>
  
  <p>I check all files setting as possible as I do, however I still have no idea how to solve this problem. I would appreciate if you can give me any suggestion.</p>