How to configure a Spring beans with properties that are stored in a database table

前端 未结 3 948
别那么骄傲
别那么骄傲 2020-12-13 04:49

In my project we\'d like to externalize the properties of our Spring managed beans, that is very easy to do with standard Java .properties files, however we want to be able

3条回答
  •  情歌与酒
    2020-12-13 05:25

    There are ways to create "PropertyPlaceholderConfigurer" Programmatically , please see below.

    Write a DAO which reads Properties and create a PropertyPlaceholderConfigurer as shown below.

    XmlBeanFactory factory = new XmlBeanFactory(new FileSystemResource("beans.xml"));
    PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
    cfg.setProperties(yourProperties);
    cfg.postProcessBeanFactory(factory);
    

提交回复
热议问题