2012-02-10 3 views
0

내 응용 프로그램은 Spring 2.5.6, Richfaces 3.1.6.SR1, JSF 1.1_02가있는 Jboss 4.2.2 GA에서 실행됩니다. 내가 원하는 것은 spert를 포함 할 귀 상자 밖에 porpertie 파일을 갖는 것입니다. 같은Spring을 사용한 PropertiesConfiguration에 대한 파일 참조

  • 정보 1 = "조이"
  • INFORMATION2는 = "디디"
  • 정보 3 = "마키"
  • [...]이 파일에

의 변화가 있어야한다 즉각적인 영향 . I는 다음과 같이 시작 :

import org.apache.commons.configuration.ConfigurationException; 
import org.apache.commons.configuration.PropertiesConfiguration; 
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy; 

[...] 

PropertiesConfiguration configure = null; 
{ 
try { 
     configure = new PropertiesConfiguration("myProperties.properties"); 
     configure.setReloadingStrategy(new FileChangedReloadingStrategy()); 
     configure.setAutoSave(true); 

    } catch (ConfigurationException e) { 
     e.printStackTrace(); 
    } 
} 

이 myProperties.properties 내 귀 내부 대상 디렉토리 어딘가에 경우 작업에만 보인다. 그래서 코드를 변경했습니다 :

File file = new File(myAppRoot + FSEP + "appserver" + FSEP + "server" + FSEP + "default" 
           + FSEP + "conf" + FSEP + "myApp" + FSEP + "myProperties.properties"); 
configure = new PropertiesConfiguration(file); 
configure.setReloadingStrategy(new FileChangedReloadingStrategy()); 
configure.setAutoSave(true); 

이 작동합니다. 하지만 절대 경로를 사용하지 않으려합니다. 이미 정의했습니다.

<bean id="myPropertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
[...] 
<property name="locations"> 
    <list> 
    <value>classpath:myProperties.properties</value> 
    <value>classpath:myApp/myProperties.properties</value> 
    </list> 
</property> 

답변

0

프로그램을 시작하는 Java에 -D 옵션을 추가 할 수 있습니다.

java ... -DjdbcPropsLocation=%YOUR_PROPERTIES_LOCATION% -DcustomInternalPropsLocation=%SOME_OTHER_PROPS_FILE_LOCATION% ... 

다음과 같은 응용 프로그램 컨텍스트에서이 옵션을 사용합니다 : 가 (파일 internal.properties에 저장된 속성이 다른 위치에게 마지막 과부하 승리를 사용하여 과부하되고 있다는주의를, 그래서 순서 예를 들어, 중요) 또는

<bean id="propsLocations" class="java.util.ArrayList" > 
    <constructor-arg> 
     <list> 
      <value>classpath:jdbc.properties</value> 
      <value>${jdbcPropsLocation}\jdbc.properties</value> 
      <!-- loading the default internal properties --> 
      <value>classpath:internal.properties</value> 
      <!-- loading the meta-data.properties --> 
      <value>classpath:meta-data.properties</value> 
      <!-- overloading the internal properties with custom values --> 
      <value>${customInternalPropsLocation}\internal.properties</value> 
     </list> 
    </constructor-arg> 
</bean> 


<bean id="propertyConfigurer" 
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="locations" > 
     <list> 
      <!-- <value>classpath:${jdbcPropsLocation}/jdbc.properties</value> --> 
      <value>classpath:jdbc.properties</value> 
      <value>${jdbcPropsLocation}\jdbc.properties</value> 
      <!-- loading the default internal properties --> 
      <value>classpath:internal.properties</value> 
      <!-- loading the meta-data.properties --> 
      <value>classpath:meta-data.properties</value> 
      <!-- overloading the internal properties with custom values --> 
      <value>${customInternalPropsLocation}\internal.properties</value> 
     </list> 
    </property> 
</bean> 

, 당신은 당신의 재산을 사용하게 애플리케이션 컨텍스트를로드하기 전에 코드에서 시스템 등록 정보 (-D)을 설정할 수 있습니다.

System.setProperty(CUSTOM_INTERNAL_PROPS_LOCATION_PROP_KEY, CUSTOM_INTERNAL_PROPS_LOCATION_PROP_VAL);