민서네집

properties 파일 안에서 다른 key 를 참조할 수 있는가? how to reference already defined property in the properties file 본문

Java

properties 파일 안에서 다른 key 를 참조할 수 있는가? how to reference already defined property in the properties file

브라이언7 2013. 8. 21. 14:25

how to reference already defined property as the value for another key in the properties file.


http://www.coderanch.com/t/469713/java/java/reference-defined-property-key-properties


내가 하고 싶은 것이 위 블로그에 나와 있는 대로 다른 key 값을 참조해서 key 값을 얻고 싶었다.


예를 들면


server.ip=http://bryan7.tistory.com


java_url={server.ip}/category/Java


내가 원하는 것은 java_url=http://bryan7.tistory.com/category/Java


이렇게 값을 원하는 것이다.


그런데, 이런 것이 java.util.Properties 클래스나 Spring 의 properties 설정 만으로 자동으로 되는 것이 아니었다.


<!-- **************************************************************** -->

<!-- Configration -->

<!-- **************************************************************** -->

<bean

class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<property name="locations">

<list>

<value>classpath:config/config.properties</value>

</list>

</property>

</bean>


<util:properties id="config" location="classpath:config/config.properties"/>


위와 같이 PropertyPlaceholder 로 자기 자신을 등록해 보아도 되지 않았다.

Spring 의 PropertyPlaceholder 의 역할은 Spring 설정 파일 안에서 값을 치환하고자 하는 목적이지 위에서처럼 Properties 파일 안에서 서로 값을 참조할 수 있도록 하는 역할은 아니었다.


이런 것을 하려면 java.util.Properties 클래스를 상속 받아서 코드를 추가해야 한다고 한다.


http://stackoverflow.com/questions/872272/how-to-reference-another-property-in-java-util-properties


http://www2.sys-con.com/ITSG/virtualcd/Java/archives/0612/mair/index.html


위 URL 에서 XProperties 클래스의 사용법과 소스 파일이 나와 있다. 나는 이것을 이용했다.


Properties 파일을 초기화 하는 방법은 


http://www.mkyong.com/java/java-properties-file-examples/


여기를 참조했다.


그밖에 Properties 파일에 대한 블로그는 다음과 같다.


< java.util.Properties 클래스를 이용한 어플리케이션의 프로퍼티 설정 >


http://javacan.tistory.com/6


< Java Properties 사용방법 >


http://umzzil.egloos.com/2175356


< Spring Properties >


http://devnote.benelog.net/java/spring/spring-properties


< 시대착오적인 설정 파일 *.properties 를 버리자 >


http://kwon37xi.egloos.com/4665590


Comments