spring로 검색한 결과 :: 시소커뮤니티[SSISO Community]
 
SSISO 카페 SSISO Source SSISO 구직 SSISO 쇼핑몰 SSISO 맛집
추천검색어 : JUnit   Log4j   ajax   spring   struts   struts-config.xml   Synchronized   책정보   Ajax 마스터하기   우측부분

회원가입 I 비밀번호 찾기


SSISO Community검색
SSISO Community메뉴
[카페목록보기]
[블로그등록하기]  
[블로그리스트]  
SSISO Community카페
블로그 카테고리
정치 경제
문화 칼럼
비디오게임 스포츠
핫이슈 TV
포토 온라인게임
PC게임 에뮬게임
라이프 사람들
유머 만화애니
방송 1
1 1
1 1
1 1
1 1
1

spring로 검색한 결과
등록일:2008-06-11 16:37:55
작성자:
제목: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