A configuration file in the Spring Boot project contains Chinese characters, but garbled characters are displayed. Procedure

First of all, this file is encoded in UTF-8, and my Intellij idea is encoded in UTF-8 by default.

Of course, instead of writing Chinese characters, change the Chinese content to Unicode (i.e., something like this: U672a \ U89C9 \ U6C60 \ U5858 \ U6625 \ U8349 \ U68a6 \ UFF0C \ U9636 \ Virtue \ U68a7 \ U53F6 \ U5DF2 \ u79CB \ U58F0) would not be a u53f6\ U5F6 \ U79CB \ U58F0). The problem is that this is so unreadable that it makes no sense to be configurable.

The encoding should be explicitly specified at read time.

How do you specify that?

So specified:

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
@PropertySource(value = "classpath:webconfig.properties",encoding = "UTF-8")
@ConfigurationProperties("web")
public class WebConfig {
    private String title;
    public String getTitle(a) {
        return title;
    }
    public void setTitle(String title) {
        this.title = title; }}Copy the code

web.properties

Web.title = The rain is beating on the window and the sky is getting coolCopy the code