본문 바로가기

개발/전자정부프레임워크

[전자정부프레임워크] properties 설정 정보 불러오기

최근 전자정부프레임워크를 사용하여 프로젝트를 진행중이다.

SpringBoot 사용할때는 .properties 파일에 설정정보를 넣어놓고 사용했는데 전자정부프레임워크에서는 xml 을 이용하여 설정정보를 저장하고 이를 사용할 수 있도록 되어있다.

 

egovframwork 로 프로젝트를 생성하면 resource 밑에 아래와 같은 구조이다.

 

 

여기서 설정정보는 context-properties.xml 에 작성하면된다.

나의 경우에는 파일경로를 저장해두고 불러오기 위해서 사용하였다.

 

1. 설정정보 입력

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">

	<bean name="propertiesService" class="egovframework.rte.fdl.property.impl.EgovPropertyServiceImpl" destroy-method="destroy">
		<property name="properties">
	        <map>
	        	<entry key="pageUnit" value="10"/>
	        	<entry key="pageSize" value="10"/>
			<entry key="fileUploadPath" value="/usr/upload"/>
	        </map>
		</property>
	</bean>
	
</beans>	

 

 

위와 같이 fileUploadPath 라는 설정정보를 추가하였다.

 

2. propertiesService 호출 

사용하려는 클래스에 아래 내용을 추가한다. 

    @Resource(name="propertiesService")
    protected EgovPropertyService propertiesService;
  

 

3. properties 사용

사용할때는 아래처럼 properteisService.getString(key) 처럼 불러오면된다

    @Override
    public void fileUpload(MultipartRequest request, HttpServletResponse response) {

        String filePath =  propertiesService.getString("fileUploadPath");

        log.info("filePath========== "+filePath);

    }

 

4. 결과확인 

실행시켜보니 로그가 정상적으로 출력된다.