Spring Boot命令行运行程序正在使用Windows默认字符编码
我在Windows上运行Spring
Boot应用程序,并使用Windows-1252编码。但是,独立的Java程序正在使用UTF-8编码。如何强制弹簧靴使用UTF-8。下面的代码输出????。我使用jar
-jar target \ spring-boot-example.jar使用以下命令
我验证了在Power Shell程序中默认字符集是Windows-1252(System.Text.Encoding):: Default
public class SpringBootConsoleApplication implements CommandLineRunner {
public static void main(String[] args) throws Exception {
SpringApplication.run(SpringBootConsoleApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
System.out.println("Default Charset=" + Charset.defaultCharset());
System.out.println("test::" +"الرياض");
}
}
我在application.properties中尝试了以下选项,但未成功:
# Charset of HTTP requests and responses. Added to the "Content-Type" header if not set explicitly.
spring.http.encoding.charset=UTF-8
# Enable http encoding support.
spring.http.encoding.enabled=true
# Force the encoding to the configured charset on HTTP requests and responses.
spring.http.encoding.force=true