• springboot-国际化


    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();
    }
    
    @Bean
    public 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;
    }
  • 相关阅读:
    在scrapy的spiders文件中设置请求时间间隔
    Python中map和reduce函数
    正则表达式
    eslint下的rules一些规则(转:备用)
    谷歌云设置xshell登录
    (过期)活动赠送的国外云服务器VPS【速度极慢,适合小白练手】
    关于服务器的那些事~~~
    call()和appy()的区别及常用场景
    javascript中使用this关键字的大总结
    懵懵懂懂、迷迷糊糊
  • 原文地址:https://www.cnblogs.com/But-you/p/10825217.html
Copyright © 2020-2023  润新知