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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:15:19+00:00 2026-05-30T09:15:19+00:00

I have a Standalone Application, this application calculates a value (Property) and then starts

  • 0

I have a Standalone Application, this application calculates a value (Property) and then starts a Spring Context.
My question is how can I add that calculated property to the spring context, so that I can use it like properties loaded from a property file (@Value("${myCalculatedProperty}"))?

To illustrate it a bit

public static void main(final String[] args) {
    String myCalculatedProperty = magicFunction();         
    AbstractApplicationContext appContext =
          new ClassPathXmlApplicationContext("applicationContext.xml");
    //How to add myCalculatedProperty to appContext (before starting the context)

    appContext.getBean(Process.class).start();
}

ApplicationContext.xml:

<bean id="propertyPlaceholderConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations" value="classpath:*.properties" />
</bean>

<context:component-scan base-package="com.example.app"/>

It is a Spring 3.0 Application.

  • 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-30T09:15:20+00:00Added an answer on May 30, 2026 at 9:15 am

    In Spring 3.1 you can implement your own PropertySource, see: Spring 3.1 M1: Unified Property Management.

    First, create your own PropertySource implementation:

    private static class CustomPropertySource extends PropertySource<String> {
    
        public CustomPropertySource() {super("custom");}
    
        @Override
        public String getProperty(String name) {
            if (name.equals("myCalculatedProperty")) {
                return magicFunction();  //you might cache it at will
            }
            return null;
        }
    }
    

    Now add this PropertySource before refreshing the application context:

    AbstractApplicationContext appContext =
        new ClassPathXmlApplicationContext(
            new String[] {"applicationContext.xml"}, false
        );
    appContext.getEnvironment().getPropertySources().addLast(
       new CustomPropertySource()
    );
    appContext.refresh();
    

    From now on you can reference your new property in Spring:

    <context:property-placeholder/>
    
    <bean class="com.example.Process">
        <constructor-arg value="${myCalculatedProperty}"/>
    </bean>
    

    Also works with annotations (remember to add <context:annotation-config/>):

    @Value("${myCalculatedProperty}")
    private String magic;
    
    @PostConstruct
    public void init() {
        System.out.println("Magic: " + magic);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that you have a standalone application (a Java application in my case)
I have a standalone application that needs to connect to a Sybase database via
I have designed a standalone application using swings which can read data from HID
I have a simple standalone application written in Visual Basic that I'm porting to
I have a WinForms Form that used to be a standalone application, but is
I have written a standalone Java application that I've packaged into a jar file
I have a standalone Java application that gets data from a database and displays
I have a standalone application in which I have to prompt the user with
I have a standalone application, and one of its duties is to take the
Hai I have developed a standalone application in which when an user logs 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.