You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(I'm sorry ,The English translation comes from the search engine Bing.com )
I was migrating the previous Spring application to the current SpringBoot application, and I found that the encoding of application.properties was ISO_8859_1, so I customized the chaset to UTF-8, but because SpringBoot's class PropertiesPropertySourceLoader is not convenient to inherit, I can only use the ugly inheritance implementation to set (Copy OriginTrackedPropertiesLoader.java to my customized java file). It is therefore expected that class plus an extended feature that allows the specified encoding to be used makes it easy to customize the character set using a concise inheritance implementation.
run the main class PropertiesdemoApplication again,see the value is right:
Refactored sample code
So I expect to expose the parameters that can be extended to the settings, and the other logic reuses the current code. So I've given an example of the refactored code under com.lizongbo.propertiesdemo.boot.env, adding the following variables
public class PropertiesPropertySourceLoader implements PropertySourceLoader {
// default charset
protected Charset charset = StandardCharsets.ISO_8859_1;
protected boolean expandLists = true;
private static final String XML_FILE_EXTENSION = ".xml";
public Charset getCharset() {
return charset;
}
public boolean isExpandLists() {
return expandLists;
}
Then my customized extend class is very simple:
public class UTF8PropertiesPropertySourceLoader extends PropertiesPropertySourceLoader {
public Charset getCharset() {
return StandardCharsets.UTF_8;
}
public boolean isExpandLists() {
return true;
}
}
Uh oh!
There was an error while loading. Please reload this page.
Versions
Spring Boot Version 2.7.2
Overview
(I'm sorry ,The English translation comes from the search engine Bing.com )
I was migrating the previous Spring application to the current SpringBoot application, and I found that the encoding of application.properties was ISO_8859_1, so I customized the chaset to UTF-8, but because SpringBoot's class PropertiesPropertySourceLoader is not convenient to inherit, I can only use the ugly inheritance implementation to set (Copy OriginTrackedPropertiesLoader.java to my customized java file). It is therefore expected that class plus an extended feature that allows the specified encoding to be used makes it easy to customize the character set using a concise inheritance implementation.
config in Spring application:
java code :
or xml code:
My custom extension steps are as follows:
go to https://start.spring.io/ , generate a gradle project with Java 8 and SpringBoot 2.7.2.
add chinese value to application.properties,just like follow:
run the main class PropertiesdemoApplication,then see the value is not right:

copy PropertiesPropertySourceLoader's code and OriginTrackedPropertiesLoader's code to my customized class UglyUTF8PropertiesPropertySourceLoader:
change StandardCharsets.ISO_8859_1 to StandardCharsets.UTF_8 in OriginTrackedPropertiesLoader.CharacterReader's construct method
Refactored sample code
So I expect to expose the parameters that can be extended to the settings, and the other logic reuses the current code. So I've given an example of the refactored code under com.lizongbo.propertiesdemo.boot.env, adding the following variables
Then my customized extend class is very simple:
refactored code diff :
the demo project in the attach file:
propertiesdemo.zip
Steps to Reproduce
other issues:
#29587
#28663
#7361
#5361
The text was updated successfully, but these errors were encountered: