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

  • Home
  • SEARCH
  • 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 4045722
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:28:11+00:00 2026-05-20T13:28:11+00:00

I have spring Java config object that loads my properties but does not override

  • 0

I have spring Java config object that loads my properties but does not override the MessageSource tokens.

@Configuration
@SuppressWarnings("unused")
public class PropertyConfiguration {

public static final String PROPERTY_OVERRIDE_URL = "d2.config.location";

@Bean
public UrlResource propertyOverrideUrl() {
    String propertyOverrideUrl = System.getProperty(PROPERTY_OVERRIDE_URL);

    UrlResource overrideUrl = null;
    // just add a bogus url as to not get a malformed URL
    try{
        overrideUrl = new UrlResource(
                (propertyOverrideUrl == null || "".equals(propertyOverrideUrl)? "file:///FILENOTFOUND" : propertyOverrideUrl)
        );
    } catch (MalformedURLException e){
        // Set the URL to a dummy value so it will not break.
        try{
            overrideUrl = new UrlResource("file:///FILENOTFOUND");
        } catch (MalformedURLException me){
            // this is a valid URL, but will not be found at runtime.
        }
    }
    return overrideUrl;
}

@Bean
@DependsOn("propertyOverrideUrl")
@Lazy(false)
public ContextAwarePropertyPlaceholderConfigurer propertyPlaceholderConfigurer()
throws IOException{
    return new ContextAwarePropertyPlaceholderConfigurer(){{
        setLocations(new Resource[]{
            new ClassPathResource("application_prompts.properties"),
            new ClassPathResource("application_webservice.properties"),
            new ClassPathResource("application_externalApps.properties"),
            new ClassPathResource("application_log4j.properties"),
            new ClassPathResource("application_fileupload.properties"),
            //Must be last to override all other resources
            propertyOverrideUrl()
        });
        setIgnoreResourceNotFound(true);
    }};
}

When I run a unit test on the javaconfig property it is fine:

    @Test
public void testOverrides__Found() throws Exception {
    setOverrideUrlSystemProperty("/target/test/resources/override-test.properties");
    context = SpringContextConfigurationTestHelper.createContext();
    context.refresh();

    String recordedPaymentConfirmationPath =
            (String)context.getBean("recordedPaymentConfirmationPath");
    assertThat(recordedPaymentConfirmationPath, is("test/dir/recordings/"));

    String promptServerUrl =
            (String)context.getBean("promptServerUrl");
    assertThat(promptServerUrl, is("http://test.url.com"));
}

But when I try the value of the MessageSource, it still has the old value:

    @Test
public void testOverrides__XYZ() throws Exception {
    setOverrideUrlSystemProperty("/target/test/resources/override-test.properties");
    context = SpringContextConfigurationTestHelper.createContext();
    context.refresh();

    String promptServerUrl = (String)context.getMessage("uivr.prompt.server.url",
                    new Object[] {}, Locale.US);

    assertThat(promptServerUrl, is("http://test.url.com"));
}

The output:

[junit] Testcase: testOverrides__XYZ took 0.984 sec
[junit]     FAILED
[junit]
[junit] Expected: is "http://test.url.com"
[junit]      got: "http://24.40.46.66:9010/agent-ivr-prompts/"
[junit]
[junit] junit.framework.AssertionFailedError:
[junit] Expected: is "http://test.url.com"
[junit]      got: "http://24.40.46.66:9010/agent-ivr-prompts/"
[junit]
[junit]     at     com.comcast.ivr.agent.configuration.PropertyOverrideConfigurationTest.testOverrides__XYZ(PropertyOverrideConfigurationTest.java:114)

Can someone please help me find a way to override the MessageSource because that is what is used in our velocity templates:

    #set($baseUrl = "#springMessage('uivr.prompt.server.url')")

I added some logging:

  @Override
  protected void loadProperties(Properties props) throws IOException {
    super.loadProperties(props);
    super.mergeProperties();
    if(logger.isDebugEnabled()){
        System.out.println("--------------------");
        for (Map.Entry entry : props.entrySet()) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
            logger.info(entry.getKey() + ":" + entry.getValue());
        }
        System.out.println("--------------------");
    }
}

And the values are printed as expected.

...
[junit] uivr.prompt.server.url:http://test.url.com
...
  • 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-20T13:28:11+00:00Added an answer on May 20, 2026 at 1:28 pm

    A couple side notes about the annotations used on your propertyPlaceholderConfigurer() @Bean method:

    • @Lazy(false) is unnecessary, as it is already the default. You can omit this.
    • @DependsOn("propertyOverrideUrl") is unnecessary, because the dependency is already established by calling propertyOverrideUrl() from within the propertyPlaceholderConfigurer()

    On to your actual question, it’s a bit tough to answer because I’m not sure what ContextAwareProperyPlaceholderConfigurer does (I’m assuming it’s a custom component as it’s not part of the core Spring Framework).

    That aside, there may simply be a misunderstanding going on. Spring’s PropertyPlaceholderConfigurer (PPC) and friends operate by post-processing bean definitions to replace ${...} placeholders, but don’t interact with MessageSource objects in any way. So the behavior you describe is, I believe, as expected: You would see the ‘correct’ URL when interrogating the bean (because it has been post-processed by your PPC), however you see the ‘incorrect’ url when interrogating the message source (because it is totally unrelated to PPC post-processing).

    Hope this helps.

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

Sidebar

Related Questions

Does Java and/or Spring have the concept of properties? I have bunch of domain
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 Java application that's very String-heavy - it takes a feed of
Let's say I have following Spring config (version of Spring is 3.0.3): <?xml version=1.0
I have a Java object which is able to configure itself given an XML
I have a bean which extends other Java file. When I create a Spring
I have a multi module Spring project that I set up using Maven: my-root
I have a Java Annotation Processor that extends from AbstractProcessor . I have two
I have a Java string of XML content. I use Velocity to generate some
I have a java string, which has a variable length. I need to put

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.