5.1 ReloadableResourceBundleMessageSource
- 使用ReloadableResourceBundleMessageSource可获得不同语言的配置
- 此处是全局配置,适合用@Bean声明
5.2 示例
5.2.1 新建英文messagesmessages_en_US.properties
wisely.name = wyf
wisely.age = 32
5.2.2 新建中文messagesmessages_zh_CN.properties
wisely.name = \u6C6A\u4E91\u98DE
wisely.age = 3-10-2
5.2.3 配置ReloadableResourceBundleMessageSource
package com.wisely.i18n;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
@Configuration
public class I18NConfig {
@Bean
public static ReloadableResourceBundleMessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource= new ReloadableResourceBundleMessageSource();
String[] resources = {"classpath:com/wisely/i18n/messages"};
messageSource.setBasenames(resources);
messageSource.setCacheSeconds(1);
return messageSource;
}
}
5.2.4 测试
package com.wisely.i18n;
import java.util.Locale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.stereotype.Component;
@Component
public class Main {
@Autowired
MessageSource messageSource;
public static void main(String[] args) {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext("com.wisely.i18n");
String nameEn = context.getMessage("wisely.name",null, Locale.US);
String nameCn = context.getMessage("wisely.name",null, Locale.CHINA);
System.out.println("nameEN="+nameEn);
System.out.println("nameCN="+nameCn);
Main main = context.getBean(Main.class);
main.showAgeInfo(context);
context.close();
}
public void showAgeInfo(AnnotationConfigApplicationContext context){
String ageEn = context.getMessage("wisely.age",null, Locale.US);
String ageCn = context.getMessage("wisely.age",null, Locale.CHINA);
System.out.println("nameEN="+ageEn);
System.out.println("nameCN="+ageCn);
}
}
输出结果
nameEN=wyf
nameCN=汪云飞
nameEN=32
nameCN=3-10-2
相关推荐
国元点睛-20230825-国元期货-23页
眼睛穴位图-睛明穴-取穴方法 方便经常上网的朋友使用
六爱护眼睛---复式统计图(第1课时).doc
图像与眼睛(2009-04-1.pdf
让消费者眼睛亮起来--稀世宝矿泉水整合营销策划案例(doc 20).doc
包含了谷歌眼睛的全部核心代码,可以用记事本、Dreamweaver、写字板、html等打开
这是一款保护眼睛的小软件,绿色软件,不需安装即可使用,试一下吧。
[最新]八年级上册物理:5.4-眼睛和眼镜-精品教案.pdf
闭着眼睛记单词-英语基础《英语1000高频词汇》
使用OpenCV1.0实现了眼睛状态识别,首先用harr检测眼睛,然后用模板匹配的方法标记眼睛状态。 程序需要使用Eyes45x11.xml Mouth25x15.xml Nose25x15.xml,将其放到C:\Program Files\OpenCV\data\haarcascades目录下...
第一部分 点睛Spring 4.x 第1 章 Spring 基础 2 1.1 Spring 概述 2 1.1.1 Spring 的简史 2 1.1.2 Spring 概述 3 1.2 Spring 项目快速搭建 5 1.2.1 Maven 简介 6 1.2.2 Maven 安装 6 1.2.3 Maven 的pom.xml 7 1.2.4 ...
opencv用于检测带眼镜的眼睛haarcascade_eye_tree_eyeglasses.xml
第一部分 点睛Spring 4.x 第1 章 Spring 基础 2 1.1 Spring 概述 2 1.1.1 Spring 的简史 2 1.1.2 Spring 概述 3 1.2 Spring 项目快速搭建 5 1.2.1 Maven 简介 6 1.2.2 Maven 安装 6 1.2.3 Maven 的pom.xml 7 1.2.4 ...
4.1人的眼睛.pdf
第一部分 点睛Spring 4.x 第1 章 Spring 基础 2 1.1 Spring 概述 2 1.1.1 Spring 的简史 2 1.1.2 Spring 概述 3 1.2 Spring 项目快速搭建 5 1.2.1 Maven 简介 6 1.2.2 Maven 安装 6 1.2.3 Maven 的pom.xml 7 1.2.4 ...
点睛-文本各种编码方式转变.7z
软件名:点睛文本编码查询 功能:本软件用于将文本的字符串转换为 Text、ASCII、Default、Unicode、BigEndianUnicode、UTF-8、UTF-7、GBK、BIG5 之间的互相转换,用于文本查询。转换结果使用十六进制表示。
内容摘要:在复杂环境中工作的机器人必须满足这样的先决条件:能够利用传感器对周围环境进行识别,具有一定的“学习”和“自我调节”能力。在市场上,有着各种依靠图像监控或力的检测来控制机器人的传感器,但是仍...
opencv用于检测眼睛。haarcascade_eye.xml文件
上网保护眼睛--网页底色修改.2011-11-25最新整理,2011-11-25最新整理...