我在Windows上運行彈簧啓動應用程序及其使用Windows-1252編碼。然而,獨立的java程序正在使用UTF-8編碼。我如何強制spring引導使用UTF-8。下面的代碼輸出????。我用下面的命令,使用廣口瓶的罐子目標\彈簧引導example.jar春季啓動命令行亞軍正在使用Windows默認字符編碼
我覈實,在電源外殼程序默認字符集爲Windows-1252(System.Text.Encoding)::默認
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
[彈簧啓動應用程序顯示的可能的重複?字符而不是unicode](https://stackoverflow.com/questions/44992808/spring-boot-application-showing-characters-instead-of-unicode) –
我已經更新了我的答案。 –
只要您使用UTF-8編碼保存源文件,它就可以在Eclipse及其控制檯上的Windows上使用。如果你試圖保存爲1252,那麼Eclipse會警告你它不會工作。我希望在Windows上看到源文件相關部分的十六進制轉儲。我懷疑它不是以UTF-8格式保存在磁盤上的。如果在磁盤上可以,那麼可能的原因是您的Windows控制檯無法呈現UTF-8。 –