Running a Spring Boot Application with fixed locale

最后都变了- 提交于 2020-12-29 12:32:29

问题


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:

  1. Setting the locale programmatically in the main method via Locale.setDefault(Locale.ENGLISH);

  2. 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?


回答1:


you can put

spring.mvc.locale=en_EN
spring.mvc.localeResolver=fixed

in your application.properties or application.yml(of course in yaml format).

Spring will automatically read those properties.

I am not aware of any other better way.




回答2:


Since SpringBoot 2.4.0 use:

spring.web.locale=en_EN
spring.mvc.localeResolver=fixed


来源:https://stackoverflow.com/questions/50763180/running-a-spring-boot-application-with-fixed-locale

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!