How to add Properties to an Application Context

后端 未结 4 1804
感情败类
感情败类 2020-12-15 20:18

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 th

4条回答
  •  清歌不尽
    2020-12-15 21:05

    Your myCalculatedProperty must be contained within one of your properties file (which are injected by the Spring propertyPlaceholderConfigurer).

    EDIT : simply use the setter, something like this

    public static void main(final String[] args) {
        String myCalculatedProperty = magicFunction();         
        AbstractApplicationContext appContext =
              new ClassPathXmlApplicationContext("applicationContext.xml");
    
        Process p = appContext.getBean(Process.class);
        p.setMyCalculatedProperty(myCalculatedProperty);
        p.start();
    }
    

提交回复
热议问题