Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Reading System property for PropertyPlaceholderConfigurer

  1. #1

    Default Reading System property for PropertyPlaceholderConfigurer

    Code:
    <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       <property name="location"><value>file:D:\MyProperties.properties</value></property>
    </bean>
    In my catalina.bat file for Tomcat.
    This entry is used to get the property values throughout the app.
    Code:
    set JAVA_OPTS=%JAVA_OPTS% -DMyProperties.fileName=D:\MyProperties.properties
    In my java code:
    Code:
    Properties properties = new Properties();
    String fileName = System.getProperty("MyProperties.fileName");
    properties.load(new DataInputStream(new FileInputStream(fileName)));
    Now at any point if the user wants to change the file path,
    then he has to change the entry in catalina.bat file as well as in 'applicationContext.xml file' for PropertyPlaceholderConfigurer.
    The valid entries for PropertyPlaceholderConfigurer are
    file:
    classpath:
    url:
    How can I force PropertyPlaceholderConfigurer to read the MyProperties.fileName entry done in catalina.bat file.
    Plz help....

  2. #2

    Default SYSTEM_PROPERTIES_MODE_OVERRIDE for PropertyPlaceholderConfigurer

    Going through the forum i have done this setting
    Code:
    <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       <property name="systemPropertiesModeName">
    	<value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
    </property>
    </bean>
    But none of my property value is read
    getting the error : Could not resolve placeholder 'MY_TRIGGER'
    Code:
    <bean id="MY_TRIGGER" class="org.springframework.scheduling.quartz.CronTriggerBean">
    	<property name="jobDetail" ref="MY_JOB" />
    	<property name="cronExpression"><value>${MY_TRIGGER}</value></property>
    </bean>

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I'm not quite sure what you are trying to do here. Does your properties file contains a property called MY_TRIGGER. If so, what you want to do here is load the actual properties file from the PropertyPlaceholderConfigurer not the property of where the properties file is. Something like your original configuration would be fine.
    Code:
    <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       <property name="location"><value>/WEB-INF/MyProperties.properties</value></property>
    </bean>

  4. #4

    Default

    My property file is placed outside the application,so I had given

    Code:
    <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       <property name="location"><value>file:D:/CLM.properties</value></property>
    </bean>
    This is workng perfectely,but now I want to change it to read the system property,
    for that I had written:
    Code:
    <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       <property name="systemPropertiesModeName">
    	<value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
    </property>
    </bean>
    But its not working..
    In short ,I want the PropertyPlaceholderConfigurer to read my System property file.

  5. #5
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I think you'll need two PropertyPlaceholderConfigurers. The first will resolve the fileLocation, this is configured to as SYSTEM_PROPERTIES_MODE_OVERRIDE but also ignoreUnresolvablePlaceholders. The second can be left as default.

  6. #6
    Join Date
    Aug 2006
    Location
    Now Germany, previously Ukraine
    Posts
    1,546

    Default

    Quote Originally Posted by Rasool View Post
    ...
    But its not working..
    In short ,I want the PropertyPlaceholderConfigurer to read my System property file.
    It is not working as it is not supposed to work. What you have done has following meaning - read properties from system properties, it it is not there, then from my property file. It is not supposed, that name of your property file is specified in the system properties, it is supposed, that properieties thmselves will be specified in system properties, e.g.

    set JAVA_OPTS=%JAVA_OPTS% -DMY_TRIGGER=some_trigger

    in this case ${MY_TRIGGER} will be resolved to "some_trigger".

    To achieve what you want you need to configure PropertyPlaceHolderConfigurer (namely, "location" property) by another PropertyPlaceHolderConfigurer (or PropertyOverrideConfigurer), while I'm not sure that it is possible. Something like this (untested!)

    Code:
    <bean id="placeholderConfigConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       <property name="systemPropertiesModeName">
    	<value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
    </property>
    <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
      <property name="location" value=${MyLocation} />
    </property>
    </bean>
    </bean>
    
    set
    Code:
    set JAVA_OPTS=%JAVA_OPTS% -DMyLocation=d:\somewhere\some.properties
    Regards,
    Oleksandr

  7. #7

    Default

    Sorry to say it again but its not working.
    Code:
    <bean id="MY_TRIGGER" class="org.springframework.scheduling.quartz.CronTriggerBean">
    	<property name="jobDetail" ref="MY_JOB" />
    	<property name="cronExpression"><value>${MY_TRIGGER}</value></property>
    </bean>
    
    <bean id="placeholderConfigConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="systemPropertiesModeName">
    		<value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
    	</property>
    </bean>
    	
    <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
      <property name="location"><value>${MyProperties.fileName}</value></property>
    </bean>
    catalina.bat File:
    Code:
    set JAVA_OPTS=%JAVA_OPTS% -DMyProperties.fileName=D:\MyProperty.properties
    In my 'MyProperty.properties' (which is placed in D:/) I have this entry
    Code:
    MY_TRIGGER=00 00 12 * * ?
    Error:
    Could not resolve placeholder 'MY_TRIGGER'

  8. #8
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I don't see setIgnoreUnresolvablePlaceholders set to true on the first PropertyPlaceholderConfigurer as I suggested earlier. The first one can't resolve all placeholders, it's only there to do the location.
    http://www.springframework.org/docs/...lders(boolean)

  9. #9

    Default

    After setting ignoreUnresolvablePlaceholders=true

    Code:
    <bean id="MY_TRIGGER" class="org.springframework.scheduling.quartz.CronTriggerBean">
    	<property name="jobDetail" ref="MY_JOB" />
    	<property name="cronExpression"><value>${MY_TRIGGER}</value></property>
    </bean>
    
    <bean id="placeholderConfigConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="systemPropertiesModeName">
    		<value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
        </property>
        <property name="ignoreUnresolvablePlaceholders">
    	<value>true</value>
      </property>
    </bean>
    	
    <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
      <property name="location"><value>${MyProperties.fileName}</value></property>
    </bean>
    Could not load properties; nested exception is java.io.FileNotFoundException : /D:/MyProperty.properties
    As you can see its starting from '/' but my actual path is D:/MyProperty.properties

  10. #10
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Ok, we are getting somewhere, it's resolved the value now. Have you tried prefixing it with "file:".
    http://www.springframework.org/docs/...resourceloader

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •