spring international

1.beans.xml setting

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basenames">
            <list>
            <!-- 其中一个资源文件,如放在com.nyan包则写com.nyan.message -->          <value>message</value>        
            </list>
        </property>
    </bean>

@src建立properties资源文件

hello,now是键名

value 的值跟properties的文件对应:<value>notice</value> --- >notice_en_US.properties>

hello=welcome,{0}
now=now is,{0}

@命名格式:message_语言_国家

message_en_US.properties

message_zh_CN.properties

@applicationContext.getMessage("键名","参数","区域")

   public void messageTest(){
        ClassPathXmlApplicationContext context = new  ClassPathXmlApplicationContext("bean.xml");
        String [] a= {"读者"};
        String hello = context.getMessage("hello", a, Locale.getDefault());
        System.out.println("default.....");
        Object [] b ={ new Date()};
        String now = context.getMessage("now", b, Locale.getDefault());

        hello = context.getMessage("hello", a, Locale.US);
        now = context.getMessage("now", b, Locale.US);

        hello = context.getMessage("hello", a, Locale.CHINESE);
        now = context.getMessage("now", b, Locale.CHINESE);

        context.close();
    }
时间: 2024-08-18 14:06:06

spring international的相关文章

spring mvc3中JACKSON序列化日期格式的问题 - 墙头草的Java - BlogJava

body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI",Tahoma,Helvetica,Sans-Serif,"Microsoft YaHei", Georgia,Helvetica,Arial,sans-serif,宋体, PMingLiU,serif; font-size: 10.5pt; line-height: 1.5;

Spring事务管理(详解+实例)

写这篇博客之前我首先读了<Spring in action>,之后在网上看了一些关于Spring事务管理的文章,感觉都没有讲全,这里就将书上的和网上关于事务的知识总结一下,参考的文章如下: Spring事务机制详解 Spring事务配置的五种方式 Spring中的事务管理实例详解 1 初步理解 理解事务之前,先讲一个你日常生活中最常干的事:取钱. 比如你去ATM机取1000块钱,大体有两个步骤:首先输入密码金额,银行卡扣掉1000元钱:然后ATM出1000元钱.这两个步骤必须是要么都执行要么都

SSM整合(spring,spirngmvc,mybatis)

整合思路   准备环境:导入jar包(spring mybatis  dbcp连接池  mysql驱动包 log4j) 工程结构: --------------------------- 1.  整合dao mybatis和spring进行整合   applicationContext-dao.xml 配置: 1.数据源 2.SqlSessionFactory 3.mapper扫描器 创建po以及mapper(通过逆向工程,这里不再演示) 针对综合查询mapper,一般情况会有关联查询,建议自定

Spring Boot 热部署

需要在pom.xml文件中加如下代码: 1 <dependencies> 2 <dependency> 3 <groupId>org.springframework.boot</groupId> 4 <artifactId>spring-boot-devtools</artifactId> 5 <optional>true</optional> 6 </dependency> 7 </depe

Spring多线程

Spring是通过TaskExecutor任务执行器来实现多线程和并发编程的.使用ThreadPoolTaskExecutor可实现一个基于线程池的TaskExecutor.而实际开发中任务一般是非阻碍的,即异步的,所以我们要在配置类中通过@EnableAsync开启对异步的支持,并通过在实际执行的Bean的方法中使用@Async注解来声明其是一个异步任务. 实例代码: (1)配置类 package com.lwh.highlight_spring4.ch3.taskexecutor; /**

Spring与JavaMail

JavaMail与Spring集成开发 spring框架集成JavaMail的主要包 2.mail.properties mail.smtp.host=smtp.163.com mail.smtp.auth=true mail.username=15511111111 mail.password=123 [email protected] 3.使用spring配置(applicationContext-mail.xml) <?xml version="1.0" encoding=

Spring Cloud ZooKeeper集成Feign的坑2,服务调用了一次后第二次调用就变成了500,错误:Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.n

错误如下: 2017-09-19 15:05:24.659 INFO 9986 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.spring[email protected]56528192: startup date [Tue Sep 19 15:05:24 CST 2017]; root of context hierarchy 2017-09-19 15:05:24.858 INFO 9986 --

Spring rabbitMq 中 correlationId或CorrelationIdString 消费者获取为null的问题

问题 在用Spring boot 的 spring-boot-starter-amqp   快速启动 rabbitMq 是遇到了个坑 消费者端获取不到:correlationId或CorrelationIdString 问题产生的原因 correlationId 的在 spring rabbitmq 2.0 以后 byte方式会被放弃,所以 目前 代码中有些地方没有改过来,应该算一个BUG @SuppressWarnings("deprecation") public class De

Spring框架之Spring AOP

一.基于注解管理的AOP 1.Spring配置文件 <!-- 配置自动扫描包,自动扫描Bean组件,切面类 --> <context:component-scan base-package="com.zhoujian.spring.anno,com.zhoujian.spring.test"> <!-- <context:include-filter type="annotation" expression="org.a