PropertyPlaceholderConfigurer to look for DB values and use properties file as fallback

后端 未结 2 501
失恋的感觉
失恋的感觉 2021-01-07 05:57

I\'m wondering if its possible to use the value in DB before properties file in PropertyPlaceholderConfigurer. So what I want to achieve is to load the properties file, and

相关标签:
2条回答
  • 2021-01-07 06:38

    PropertyPlaceholderConfigurer has a "properties" property that can point to an object that retrieves the database values. See an example here: http://pure-essence.net/2011/02/10/spring-loading-properties-from-database-with-a-twist/

    Also, you'll want to set "ignoreUnresolvablePlaceholders" to true on the bean that config that loads the properties from the database. That way you can add another PropertyPlaceholderConfigurer as a fallback to provide properties that are not found in the database.

    0 讨论(0)
  • 2021-01-07 06:41

    Since you want to merge properties, you may want to implement InitializingBean on your target bean. Your hook will be the afterPropertiesSet method, where you can go about with your kung-fu.

    BTW, Spring loads and overrides beans definitions in the order the container encounters it.

    0 讨论(0)
提交回复
热议问题