Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 786437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:02:28+00:00 2026-05-14T21:02:28+00:00

My problem is as follows: I have server.properties for different environments. The path to

  • 0

My problem is as follows:

I have server.properties for different environments. The path to those properties is provided trough a system property called propertyPath. How can I instruct my applicationContext.xml to load the properties with the given propertyPath system property without some ugly MethodInvokingBean which calls System.getProperty('');

My applicationContext.xml

<bean id="systemPropertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
        <property name="placeholderPrefix" value="sys{"/>
        <property name="properties">
            <props>
                <prop key="propertyPath">/default/path/to/server.properties</prop>
            </props>
        </property>
    </bean>


    <bean id="propertyResource" class="org.springframework.core.io.FileSystemResource" dependency-check="all" depends-on="systemPropertyConfigurer">
        <constructor-arg value="sys{propertyPath}"/>
    </bean>

    <bean id="serviceProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="location" ref="propertyResource"/>
    </bean>

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" ref="propertyResource"/>
        <property name="placeholderPrefix" value="prop{"/>

        <property name="ignoreUnresolvablePlaceholders" value="true"/>
        <property name="ignoreResourceNotFound" value="false"/>
    </bean>

    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
         <property name="jndiName" value="prop{datasource.name}"/>
    </bean>

with this configuration the propertyResource alsways complains about

java.io.FileNotFoundException: sys{propertyPath} (The system cannot find the file specified)

Any suggestions? 😉
Thanks gabe

EDIT:

Now I debugged the loading process of the beans and it seems the setLocation Method of the propertyConfigurer is called before the systemPropertyConfigurer is created so the propertyResource is initialized with “sys{propertyPath}”.
I played around with depends-on but no luck.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:02:28+00:00Added an answer on May 14, 2026 at 9:02 pm

    Ok. I solved it. The problem is both of my PropertyPlaceholders are BeanFactoryPostProcessor those get processed after the context is loaded but the properties are set after. So it is impossible to populate one PropertyPlaceholder with another.

    Here is my solution in code 😉

    package property.util;
    
    import org.apache.commons.lang.StringUtils;
    import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
    import org.springframework.core.io.FileSystemResource;
    import org.springframework.core.io.Resource;
    
    import java.io.IOException;
    import java.util.Properties;
    
    /**
     * ConfigurablePropertyPlaceholder takes instructions which SystemProperty
     * contains the path to the propertyfile to load.
     *
     * @author Gabe Kaelin
     * 
     */
    public class ConfigurablePropertyPlaceholder extends PropertyPlaceholderConfigurer {
    
    
        private String propertyLocationSystemProperty;
        private String defaultPropertyFileName;
    
    
        public String getPropertyLocationSystemProperty() {
            return propertyLocationSystemProperty;
        }
    
        public void setPropertyLocationSystemProperty(String propertyLocationSystemProperty) {
            this.propertyLocationSystemProperty = propertyLocationSystemProperty;
        }
    
        public String getDefaultPropertyFileName() {
            return defaultPropertyFileName;
        }
    
        public void setDefaultPropertyFileName(String defaultPropertyFileName) {
            this.defaultPropertyFileName = defaultPropertyFileName;
        }
    
        /**
         * Overridden to fill the location with the path from the {@link #propertyLocationSystemProperty}
         *
         * @param props propeties instance to fill
         * @throws IOException
         */
    
        @Override
        protected void loadProperties(Properties props) throws IOException {
            Resource location = null;
            if(StringUtils.isNotEmpty(propertyLocationSystemProperty)){
    
                String propertyFilePath = System.getProperties().getProperty(propertyLocationSystemProperty);
                StringBuilder pathBuilder = new StringBuilder(propertyFilePath);
    
                if(StringUtils.isNotEmpty(defaultPropertyFileName) && !propertyFilePath.endsWith(defaultPropertyFileName)){
                    pathBuilder.append("/").append(defaultPropertyFileName);
                }
    
                location = new FileSystemResource(pathBuilder.toString());
            }
    
            setLocation(location);
            super.loadProperties(props);
        }
    }
    

    The according applicationContext.xml entry

    <bean id="propertyConfigurer" class="property.util.ConfigurablePropertyPlaceholder">
      <property name="propertyLocationSystemProperty" value="propertyPath" />
      <property name="defaultPropertyFileName" value="server.properties" />
      <property name="ignoreResourceNotFound" value="false"/>
    </bean>
    

    the java process can be started with

    java -DpropertyPath=/path/to/properties
    

    and it loads the properties and they are available in the applicationContext.xml

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem Assumption: I have a table in SQL Server, with the structure as follows;
Newbie here! My problem is as follows: I have a dynamically populating ul where
I'm facing a problem that I can summarize as it follows: I have a
My problem is as follows. I have an array of objects in the form
I have a mysql problem, my query looks as follows but not complete SELECT
Greetings, I have a problem as follows: I have an SQL variable declared: DECLARE
My scenario is as follows: I have a client-server application. The client is deployed
Well, the problem is as follows: I have a WPF Application built using the
The problem we have are as follows: We are using ANT to build our
i have a server that is as follows: import java.io.*; import java.net.*; import java.util.StringTokenizer;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.