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 7853707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:46:31+00:00 2026-06-02T19:46:31+00:00

I have a Spring application-context.xml with PropertyPlaceholderConfigurer to get properties’ values from .properties file.

  • 0

I have a Spring application-context.xml with PropertyPlaceholderConfigurer to get properties’ values from .properties file. Main and test source folders have separate .properties file. The issue is that I need to use environment variables in .properties file. But when I do it in the following way:

property.name=${env.SYSTEM_PROPERTY}

I’m getting the following error:

org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'beanName' defined in class path resource [com/example/applicationContext.xml]: Could not resolve placeholder 'env.SYSTEM_PROPERTY'

while placeholder configurer defined as

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:com/example/application.properties"/>
</bean>

Any ideas how-to make property.name be interpreted as environment variable (and not as placeholder)?

Best regards, Dmitriy.

  • 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-06-02T19:46:32+00:00Added an answer on June 2, 2026 at 7:46 pm

    I’d probably change the solution completely: inject the system property directly, as opposed to injecting the property which refers to a system property

    E.g.

    @Value("#{ systemProperties['JAVA_MY_ENV'] }") 
    private String myVar;
    

    or

    <property name ="myVar" value="#{systemProperties['JAVA_MY_ENV']}"/>
    

    I use a property placeholder configurer like this

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <property name="locations">
        <list>
            <value>classpath:someprops.properties</value>
        </list>
      </property>
      <property name="ignoreResourceNotFound" value="true" />
      <property name="searchSystemEnvironment" value="true" />
      <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
    

    You must also remember to pass the parameter into the program using

     -DJAVA_MY_ENV=xyz
    

    This way when you run the production version you can pass one thing and when you are running tests another.

    Also what I often what I do is something like this:

      <property name="locations">
        <list>
          <value>classpath:someprops.properties</value>
          <value>classpath:someprops-{environment}.properties</value>
        </list>
      </property>
    

    where environment is prod/stage/test/int/ci/local (1 per environment – you may only have 2 or 3 for now). You can pass the environment variable to the program. Any properties which should be the same regardless of if its production/running on your local pc/tests would be in the someprops.properties property file. Any ones specific to the environment/way its being run as will go in the more specific file (you should put it in the someprops.properties file as well as a default unless overridden mechanism)

    E.g.
    in classpath:someprops.properties

    url=www.mysite.com
    

    in classpath:someprops-local.properties

    url=localhost
    

    By using this basic idea you can separate tests and the program’s normal running properties in a clean manner.

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

Sidebar

Related Questions

In my spring application context file, I have something like: <util:map id="someMap" map-class="java.util.HashMap" key-type="java.lang.String"
I have a spring map declare in the application context xml like this: <map>
Can you create a List in a Spring application-context.xml file without using the <list>
I have a java application that use spring with a spring.xml file in the
I have a Spring Web application with an applicationContext.xml loaded through a ContextLoaderListener in
I am using spring/hibernate. i have configured 5 datasources in applicationContext.xml file. All datasources
I have properties file report.properties (\WEB-INF\classes\properties\report.properties) with entry : reportTemplate = reports/report5.jrxml and applicationContext-reports.xml
I have a spring web application (currently packaged as a war file) which I
In spring/junit you can load application context files using @ContextConfiguration such as @ContextConfiguration({classpath:a.xml, classpath:b.xml})
I have a large application spread across multiple Spring bean definition xml files. In

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.