Spring Boot命令行运行程序正在使用Windows默认字符编码 [英] spring boot commandline runner is using windows default character encoding

查看:377
本文介绍了Spring Boot命令行运行程序正在使用Windows默认字符编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows上运行Spring Boot应用程序,并使用Windows-1252编码.但是,独立的Java程序正在使用UTF-8编码.如何强制弹簧靴使用UTF-8.下面的代码输出????.我通过jar -jar target \ spring-boot-example.jar

I am running spring boot application on windows and its using windows-1252 encoding. However stand alone java program is using UTF-8 encodeing. How do I force spring boot to use UTF-8. below code outputs ????. I use the below command using jar -jar target\spring-boot-example.jar

我已验证在Power Shell程序中默认字符集为Windows-1252(System.Text.Encoding):: Default

I verified that in power shell program that default character set is 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中的以下选项,但没有成功:

I tried the below options in application.properties without success:

# 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

推荐答案

@AbjitSarkar @JC Carrillo这个问题似乎与Windows环境有关.我在UbuntuVM上部署了相同的代码,一切似乎都很好.

@AbjitSarkar @JC Carrillo this issue seems to be with windows environment. I deployed the same code on UbuntuVM and everything seems to be fine.

感谢您的倾听,并给了我探索的秘诀!

Thank you for listening to me and giving me tips to explore !!

这篇关于Spring Boot命令行运行程序正在使用Windows默认字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆