MessageSource :: 스프링(spring)/아이바티스(IBatis)/하이버네이트(Hibernate)[SSISO Community]
 
SSISO 카페 SSISO Source SSISO 구직 SSISO 쇼핑몰 SSISO 맛집
추천검색어 : JUnit   Log4j   ajax   spring   struts   struts-config.xml   Synchronized   책정보   Ajax 마스터하기   우측부분

스프링(spring)/아이바티스(IBatis)/하이버네이트(Hibernate)
[1]
등록일:2008-06-11 16:37:55 (0%)
작성자:
제목:MessageSource

스프링은 지역 및 언어 맞는 메시지를 출력할 수 있도록  

org.springframework.context.MessageSource 인터페이스를 제공하고 있다.   

 

ApplicationContext 는 MessageSource 인터페이스를 구현하고 있으며

등록된 빈 객체중에 MessageSource 타입의 빈 객체를 이용하여 메시지를 처리한다.

그러므로 설정파일에 messageSource 빈 객체를 정의해줘야 한다.

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">

   <property name="basename">

         <value>message.name</value>

   </property>

</bean>

 ResourceBundleMessageSource 는 MesageSource 인터페이스 구현 클래스로 

 basename 에 전달된 값은 mesage 패키지안에 name 프로퍼티 파일로부터 메시지를 가져온다는 의미이다.

 지역별로 패키지이름_local코드.properties 로 구분하여 메시지를 지원할 수 있다.

  • message.properties -> 기본 메시지 (해당 local 에 맞는 파일이 존재 하지 않은 경우 사용)
  • message_en.properties -> 영어
  • message_ko.properties -> 한글  

빈 객체에서 메시지를 이용할려면 아래와 같이 두가지 방법을 이용하여 구현하면 된다.

String message = messageSource.getMessage("message.hi" , new String[] {userName} , Locale.getDefault());

[출처] MessageSource |작성자 jiruchi

[본문링크] MessageSource
[1]
코멘트(이글의 트랙백 주소:/cafe/tb_receive.php?no=30335
작성자
비밀번호

 

SSISOCommunity

[이전]

Copyright byCopyright ⓒ2005, SSISO Community All Rights Reserved.