简体   繁体   English

在Spring Boot中从application.properties配置国际化

[英]Configure internationalization from application.properties in spring boot

I was wondering if I can configure how spring boot handles internationalization using the application.properties file instead of writing it in code. 我想知道是否可以使用application.properties文件而不是用代码配置Spring Boot如何处理国际化。

For example: To define a LocaleChangeInterceptor I have to declare a bean like this: 例如:要定义LocaleChangeInterceptor我必须像这样声明一个bean:

<bean id="localeChangeInterceptor"
      class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
    <property name="paramName" value="lang" />
</bean>

However, a look at the most used properties in the documentation shows only 3 values that can be configured for internationalization: 但是,查看文档中最常用的属性后,仅显示了可以配置为国际化的3个值:

# INTERNATIONALIZATION (MessageSourceAutoConfiguration)
spring.messages.basename=messages
spring.messages.cache-seconds=-1
spring.messages.encoding=UTF-8

So is there a way to achieve this? 那么有没有办法做到这一点? is there a convention on how to map this to a properties file? 是否有关于如何将此映射到属性文件的约定?

is there a convention on how to map this to a properties file? 是否有关于如何将此映射到属性文件的约定?

No there isn't. 不,没有。 It's only a single bean definition and it's entirely optional, so I would prefer to leave that in Java. 它只是一个bean定义,并且是完全可选的,因此我宁愿将其保留在Java中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 来自application.properties的Spring Boot配置 - Spring Boot configuration from application.properties Spring Boot 2:如何使用application.properties文件配置HikariCP - Spring Boot 2: How to configure HikariCP using application.properties file Spring Boot - 从 application.yml 和 application.properties 注入 - Spring Boot - inject from application.yml and application.properties 如何配置Spring以从jar外部加载application.properties? - How to configure Spring to load application.properties from outside of jar? 春季启动:从“ application.properties”读取文件路径 - Spring boot: Read a file PATH from “application.properties” spring 引导中的@value 未从 application.properties 提供值 - @value in spring boot not giving value from application.properties 为什么 Spring 引导不从默认的 application.properties 文件中读取 - Why is Spring Boot not reading from default application.properties file spring 从 bean 数据引导 application.properties 值 - spring boot application.properties value from bean data Spring Boot - 从依赖的 jar 加载 application.properties/yml - Spring Boot - Load application.properties/yml from dependent jar Spring Boot - 无法从application.properties解析xml中的属性 - Spring Boot - property could not be resolved in xml from application.properties
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM