@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을 사용하시면 됩니다.

'JAVA > Spring(eGovFrame)' 카테고리의 다른 글

Custom Validation Annotion 생성  (0) 2015.08.26
[ERROR] Ambiguous mapping found.  (0) 2015.08.26
Spring4 Scheduling - Application  (0) 2015.05.19
Spring4 Scheduling - Demon  (0) 2015.05.19
Spring4 Scheduling - Spring 설정  (0) 2015.05.19

+ Recent posts