使用固定的语言环境运行Spring Boot应用程序 [英] Running a Spring Boot Application with fixed locale
问题描述
我在没有用户前端的服务器应用程序上工作.为了确保应用程序的所有部分仅生成英语消息,我想确保应用程序仅使用特定的语言环境.
I am working on a server application without a user frontend. To ensure that all parts of the application will generate only English message I would like to ensure that the application will use only a specific locale.
在阅读了文档并进行了一些谷歌搜索后,我得出的结论是我必须执行以下操作:
After reading the docs and some googling I came to the conclusion that I have to do the following:
-
通过
Locale.setDefault(Locale.ENGLISH)
;
提供 FixedLocaleResolver
的bean实例作为应用程序的语言环境解析器.
Provide a bean instance of FixedLocaleResolver
as locale resolver for the application.
这是正确的还是实现我的目标的更好方法?
Is this correct or this there a better way to achive my goal?
推荐答案
您可以放
spring.mvc.locale=en_EN
spring.mvc.localeResolver=fixed
在您的application.properties或application.yml中(当然是yaml格式).
in your application.properties or application.yml(of course in yaml format).
Spring会自动读取这些属性.
Spring will automatically read those properties.
我不知道还有其他更好的方法.
I am not aware of any other better way.
这篇关于使用固定的语言环境运行Spring Boot应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!