Code Monkey home page Code Monkey logo

Comments (2)

qqxx6661 avatar qqxx6661 commented on July 30, 2024

之前这块就发现有点问题但没有深究,但是中文的msg应该是可以支持的,之后有空看下。

from log-record.

qqxx6661 avatar qqxx6661 commented on July 30, 2024

初步研究了下,目前大部分版本spring和springboot的application.properties默认都是ISO-8859-1。所以如果想要在配置里写中文,有两种方式:

  • 使用方自行修改springboot的application.properties编码方式到UTF-8,这样可以直接在配置中写中文,比如:
    • 在自己的IDEA中更改编码方式。在setting中的File Encodings里修改配置文件编码方式至UTF-8
    • 通过设置spring.mandatory-file-encoding=UTF-8来要求应用程序必须使用UTF-8编码来读取配置文件。这个设置可以在application.properties文件或JVM启动参数中进行配置。
  • 使用方无法修改或者不想修改application.properties到UTF-8编码,那么在ISO-8859-1下,想输入中文,使用方就需要将中文转为unicode格式后写在application.properties。上面你贴的图中,我的配置读取方式就是一种兼容方式(读取到的ISO-8859-1编码的字符串重新编码为UTF-8)。实际上,还有一些方式能够绕过application.properties的默认编码方式,比如支持使用方通过环境变量或启动参数来设置这些配置,但是为了一个格式化配置设置在环境变量或者JVM参数里显得太过侵入性了。
  • 将配置移除application.properties,改为自定义的类似log-record.properties,指定为UTF-8读取配置。同样需要用户以UTF-8读写配置,其实没区别。

参考:
https://umm.js.org/p/e678b765/
https://kucw.io/blog/2021/7/spring-chinese-properties/

from log-record.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.