博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
springboot-国际化
阅读量:7008 次
发布时间:2019-06-28

本文共 1506 字,大约阅读时间需要 5 分钟。

https://blog.csdn.net/liujun03/article/details/82775634

一、国际化基本原理

在Spring程序中,国际化主要是通过ResourceBundleMessageSource这个类来实现的,那么下面我们分析一下Spring Boot是如何实现国际化支持的。
Spring Boot通过MessageSourceAutoConfiguration是为我们自动配置好了管理国际化资源文件的组件的: org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration

@Bean@ConfigurationProperties(    prefix = "spring.messages")public MessageSourceProperties messageSourceProperties() {    return new MessageSourceProperties();}@Beanpublic MessageSource messageSource() {    MessageSourceProperties properties = this.messageSourceProperties(); //private String basename = "messages";    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();    if (StringUtils.hasText(properties.getBasename())) {        messageSource.setBasenames(StringUtils.commaDelimitedListToStringArray(StringUtils.trimAllWhitespace(properties.getBasename())));    }    if (properties.getEncoding() != null) {        messageSource.setDefaultEncoding(properties.getEncoding().name());    }    messageSource.setFallbackToSystemLocale(properties.isFallbackToSystemLocale());    Duration cacheDuration = properties.getCacheDuration();    if (cacheDuration != null) {        messageSource.setCacheMillis(cacheDuration.toMillis());    }    messageSource.setAlwaysUseMessageFormat(properties.isAlwaysUseMessageFormat());    messageSource.setUseCodeAsDefaultMessage(properties.isUseCodeAsDefaultMessage());    return messageSource;}

 

转载于:https://www.cnblogs.com/But-you/p/10825217.html

你可能感兴趣的文章
基层公务员自述:每天擦桌子证明自己还活着(全文)
查看>>
我的友情链接
查看>>
WordPress内外网访问的问题解决
查看>>
centos: 建立git账户
查看>>
Maven|项目命令
查看>>
python filter, map, 和reduce
查看>>
memcached 异常 : 单数据项超过默认值1m
查看>>
mysql创建登录报错ERROR1045(28000)
查看>>
virtualbox(windows环境下)centos虚拟机安装增强工具
查看>>
BZOJ2325[ZJOI2011]道馆之战——树链剖分+线段树
查看>>
MyBatis学习总结(二)——使用MyBatis对表执行CRUD操作
查看>>
LAMP简单架构实验:Apache+NFS+MySQL
查看>>
ll命令
查看>>
Linux操作系统68问(下)
查看>>
Windows2008R2跨林迁移用户、计算机(6)
查看>>
Linux怎么添加图形界面组件
查看>>
POJ_1001 Exponentiation
查看>>
邮件附件在线预览——HTML Filter
查看>>
PC桌面右下方QQ托盘图标
查看>>
jenkins执行启动java程序后,会杀掉程序的解决方法
查看>>