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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:09:01+00:00 2026-06-05T15:09:01+00:00

Our web app uses SystemPropertyPlaceholder to load property files depending on the value of

  • 0

Our web app uses SystemPropertyPlaceholder to load property files depending on the value of a system property (see below)

The default setup for running it locally is stored in application.properties. On the production server we currently just set “env” to “production” before deploying the app and it will load production.properties.

Now for testing the app a test.properties file should be used.

If I run all of the tests say in our jenkins build, adding -Denv=test will work as expected. But what if I just want to run a single test in Eclipse with the integrated JUnit runner?

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = WebContextLoader.class, locations = {"classpath:application-context.xml" })
public class SomeTest {

Is there any way to tell my test it should set the system property “env” to “test” BEFORE Spring is loaded up? Because using MethodInvokingFactoryBean will only set it afterwards for some reason, even if I set it before loading my property files:

<bean id="systemPrereqs"
    class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject" value="#{@systemProperties}" />
    <property name="targetMethod" value="putAll" />
    <property name="arguments">
        <!-- The new Properties -->
        <util:properties>
            <prop key="env">test</prop>
        </util:properties>
    </property>
</bean>

<bean
    class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
    <property name="searchContextAttributes" value="true" />
    <property name="contextOverride" value="true" />
    <property name="ignoreResourceNotFound" value="true" />
    <property name="locations">
        <list>
            <value>classpath:application.properties</value>
            <value>classpath:${env}.properties</value>
            <value>${config}</value>
        </list>
    </property>
</bean>

<bean id="managerDataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="username">
        <value>${database.username}</value>
    </property>
    <property name="password">
        <value>${database.password}</value>
    </property>
    <property name="url">
        <value>${database.url}</value>
    </property>

</bean>

With the database properties defined inside application.properties, production.properties and test.properties.

The point is, of course that I want to use the same context file for all environments, otherwise I could just tell my test to use a different context where I set The PropertyPlaceholder property “location” to test.properties… But I want my tests to also cover my context so that any errors there are caught as early as possible (I’m doing end to end tests on our web app with spring-web-mvc which loads up the entire web app providing some nice feedback there and I don’t want to loose that).

So far the only way I can see might be to configure the JUnit runner to include some system property setting argument, though I don’t know how to do that..

  • 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-05T15:09:02+00:00Added an answer on June 5, 2026 at 3:09 pm

    I am working on exactly the same problem now and hopefully found the way. You can call System.setProperty() into the static initializer of your test case.

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

Sidebar

Related Questions

Background: Our web app uses the jquery.constrain.js plugin to handle data entry in some
in our web-app project, we include some jar files. For patching some issues of
We want to encrypt all our web app configuration files that we deploy to
My company uses virtual machines for our web/app servers. This allows for very easy
Our web app uses the Google CDN to link to the jQuery library and
I have a .net v4 web app which uses impersonation as our web server
Our web app needs to be made PCI compliant, i.e. it must not store
We have encountered a very strange class not found problem in our web app
Our client's web app restarts suddenly at random intervals. For each restart, we've found
We use ELMAH for our ASP.NET web app and I am stumped as to

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.