It works well when I set my properties in application.yml directly But when I set these properties in additional file imported by "spring.config.import" like below, its charset is wrong Is there some options to set charset for "spring.config.import"? Otherwise I have to use @PropertySource to set charset, but it do not support yml file SpringBoot Provide a configuration option to load properties config data files as UTF-8

Comment From: wilkinsona

What do you mean by wrong? Which charset did you expect to be used and which charset was actually used? Can you provide a minimal sample that reproduces the problem so that we can see exactly what you mean? You can share one with us by zipping it up and attaching it to this issue or by pushing it to a separate repository on GitHub.

Comment From: lfz757077613

What do you mean by wrong? Which charset did you expect to be used and which charset was actually used? Can you provide a minimal sample that reproduces the problem so that we can see exactly what you mean? You can share one with us by zipping it up and attaching it to this issue or by pushing it to a separate repository on GitHub.

you can try this demo project, all of files are utf8. I have tried to debug to locate the cause, but its a little complex to find where run the decoding code.. If I use @PropertySource(value = {"classpath:other.properties"}, encoding = "UTF-8") instead of "spring.config.import", it works fine

SpringBoot Provide a configuration option to load properties config data files as UTF-8

springtest.zip

Comment From: wilkinsona

Java's default encoding for properties files is ISO-8859-1 and we deliberately align with this (see https://github.com/spring-projects/spring-boot/issues/5361 and https://github.com/spring-projects/spring-boot/pull/10565). As recommended in Properties' javadoc you should use Unicode escapes for non-Latin1 characters. YAML uses UTF-8 by default which is why the value of static-config.right is correct.

We can consider offering a setting to load .properties files using UTF-8 but it will be somewhat difficult to set as it creates something of chicken and egg problem.

Comment From: lfz757077613

Thanks! I understand, this case confused me a long time. For now, I think "yml" is more convenient than "properties" in springboot project. Perhaps "spring.config.import" should provide a prefix for encoding such like "optional" prefix. Thanks again.

Comment From: philwebb

We'd like to see how the UTF-8 switch planned for Java 18 works out before we do anything in Spring Boot. For now, using YAML seems like the best approach.