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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:47:05+00:00 2026-06-11T09:47:05+00:00

Working with Java Spring, how can I overwrite the default behavior of the property-placeholders

  • 0

Working with Java Spring, how can I overwrite the default behavior of the property-placeholders to return ‘foo’ for any property?

The current path I’m going down is to extend PropertySource as follows:

public class FooPropertySource extends PropertySource<Object> {
    private static final String DEFAULT_NAME = "foo";

    public FooPropertySource() {
        super(DEFAULT_NAME, null);
    }

    @Override
    public Object getProperty(String name) {
        return "foo";
    }
}

At this point, I have two questions:

A) What do I do with my application Context XML file? As of now, I’ve defined this as a bean…That’s about it.

B) Do I have to do anything in code to load other beans from my application context, such that they will use the FooPropertySource?

Thanks

  • 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-11T09:47:07+00:00Added an answer on June 11, 2026 at 9:47 am

    You will have to register this PropertySource to be added to your application context. If you manually starting up your application context, you can do this:

        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext();
        ctx.setConfigLocation("applicationContext.xml");
        ctx.getEnvironment().getPropertySources().addLast(new FooPropertySource());
        ctx.refresh();
    

    If you are doing this in a web environment, you will have to register a custom ApplicationContextInitializer to intercept the application context before it is refreshed to inject in your PropertySource:

    public class CustomInitializer implements ApplicationContextInitializer<ConfigurableWebApplicationContext> {
        public void initialize(ConfigurableWebApplicationContext ctx) {
            ctx.getEnvironment().getPropertySources().addLast(new FooPropertySource());
        }
    }
    

    More details here

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

Sidebar

Related Questions

We are working on Java web project based on JPA 2, Hibernate, Spring 3
I am working on a Java app that uses Spring IoC and JDBC Template
I'm working on a Java web application (Adobe Flex front-end, JPA/Hibernate/BlazeDS/Spring MVC backend) and
I am working on an application using Spring 3 and Hibernate 3.5 with Java
While working with Spring 3.x and and JSF 2.x, we can register the Spring
My Login Form is not working ,Can any please help me... public class LoginServlet
I'm working on code for a Java project, I currently have replaceAll(String, int) in
I have a performance problem related to string comparison (in Java). I'm working on
I am working Java EE application. Requirements are very less as of now, only
While working with Java, I find it hard to position my main window 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.