GMs*_*soF 5 java spring spring-mvc internationalization spring-boot
我正在将 spring MVC 转换为 spring boot (2.0.3.RELEASE) 项目。
我在 spring boot 中使用它,它有效:
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasenames("classpath:/locale/normal/message", "classpath:/locale/validation/message");
messageSource.setDefaultEncoding("UTF-8");
return messageSource;
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用 spring boot 自动配置(通过application.properties)如下(删除上面的手动 bean 配置):
spring.messages.basename=classpath:/locale/normal/message,classpath:/locale/validation/message
Run Code Online (Sandbox Code Playgroud)
我在下面尝试过,它也不起作用:
spring.messages.basename=/locale/normal/message,/locale/validation/message
Run Code Online (Sandbox Code Playgroud)
我在下面阅读了他们的文档:
# INTERNATIONALIZATION (MessageSourceProperties)
spring.messages.always-use-message-format=false # Whether to always apply the MessageFormat rules, parsing even messages without arguments.
spring.messages.basename=messages # Comma-separated list of basenames (essentially a fully-qualified classpath location), each following the ResourceBundle convention with relaxed support for slash based locations.
spring.messages.cache-duration= # Loaded resource bundle files cache duration. When not set, bundles are cached forever. If a duration suffix is not specified, seconds will be used.
spring.messages.encoding=UTF-8 # Message bundles encoding.
spring.messages.fallback-to-system-locale=true # Whether to fall back to the system Locale if no files for a specific Locale have been found.
spring.messages.use-code-as-default-message=false # Whether to use the message code as the default message instead of throwing a "NoSuchMessageException". Recommended during development only.
Run Code Online (Sandbox Code Playgroud)
我将消息属性文件放在类路径中:
src\main\resources\locale\normal
src\main\resources\locale\validation
Run Code Online (Sandbox Code Playgroud)
我尝试了很多组合,但都不起作用,为什么?
我遇到的错误:
javax.servlet.jsp.JspTagException: No message found under code 'login.timeout' for locale 'en'.
Run Code Online (Sandbox Code Playgroud)
(我很确定消息代码在我的所有语言环境的属性文件中。)
我正在使用 Spring 标签加载本地化消息:
<spring:message code="${param.error}" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2282 次 |
| 最近记录: |