About the solution to the problem of reading a property profile in the spring boot with Chinese garbled __spring

Source: Internet
Author: User

Original link: http://www.zslin.com/web/article/detail/47


Problem Description

When there is Chinese in the configuration file of. Properties, the reads are always garbled. For example, the contents of my application.properties configuration file are as follows:

server.port=9090
test.msg= Hello: springboot

When reading the test.msg value in the program will always get garbled, the default is to read in iso-8859-1 character encoding, the method to try is:

1. Add Configuration

Banner.charset=utf-8
server.tomcat.uri-encoding=utf-8
spring.http.encoding.charset=utf-8
Spring.http.encoding.enabled=true
spring.http.encoding.force=true
spring.messages.encoding=utf-8

2. Set File type

Modify the Application.properites file type to the UTF-8 encoding type.

The above method tests to obtain the value or garbled. • Solutions

To set the transparent NATIVE-TO-ASCII conversion for File encodings to true, follow these steps: click

File-> Settings-> Editor-> file encodings

Set the default encoding for properties files under Properties Files (*.properties) to UTF-8 to Transparent NATIVE-TO-ASCII Conversion before the check on the selection.


This is one of the most common solutions on the Web, but when you develop under Eclipse, you will find that the corresponding transparent NATIVE-TO-ASCII conversion settings option is not found at all.


So how do you solve the problem of Chinese garbled in the Spring boot read configuration file under Eclipse?

First of all, the analysis of the role of transparent NATIVE-TO-ASCII conversion settings, Chinese translation is transparent native-to-ascii conversion.

Analysis is that the property files in Eclipse are converted to ASCII code to be parsed.

Baidu Search, eclipse how to set the properties file transparent Native-to-ascii conversion

Get: Install properties plugin propertieseditor and settings in Eclipse (drawings), ASCII code to Chinese

Http://www.cnblogs.com/zdz8207/p/java-eclipse-properties.html

It is recommended to use offline installation inside.

After the installation completes the Propertieseditor plug-in, use the editor to edit the Chinese in the property file again, and then rerun the program.

Found that the read Chinese configuration file is not garbled.






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.