JAVA/Spring(eGovFrame)

@PropertySource를 이용하여 Property 등록

최강깜시 2015. 5. 19. 14:38

@PropertySource로 Property 파일을 Evnironment로 로딩을 합니다.

아래는 예제 Sample입니다.

package com.intercast.schedule.dao;

 

import javax.annotation.Resource;

 

import org.springframework.context.MessageSource;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Repository;

 

@Repository("excelDao")
@PropertySource("classpath:properties/globals.properties")
public class ExcelDao {

 

 @Resource
 private MessageSource messageSource;

 

 @Resource
 private Environment environment;

 

 public void getExcelInfo() {
  System.out.println( "UPLOAD_FILE_PATH : " + environment.getProperty("UPLOAD_FILE_PATH") );
 }


}

 

굵은 글씨로 표시 한 부분이 해당 property를 inject 하고 사용하는 곳입니다.

프로퍼티가 여러개 일 경우에는 @PropertySources Annotation을 사용하시면 됩니다.