PropertyPlaceholderConfigurer查找数据库值并将属性文件用作后备 [英] PropertyPlaceholderConfigurer to look for DB values and use properties file as fallback

查看:159
本文介绍了PropertyPlaceholderConfigurer查找数据库值并将属性文件用作后备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能在PropertyPlaceholderConfigurer中使用属性文件之前的DB中的值.因此,我要实现的是加载属性文件,并且如果数据库中存在任何键,请使用该文件.现在我不知道从哪里开始,但是我假设有一个可以重写的方法/类或需要实现的接口.

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 if any keys exist in the database, use that. Right now I don't know where to start, but I'm assuming that there is a method/class that I can override or interface that I need to implement.

仅提及方法/类/接口,我将很高兴从这里开始. TIA

Just mention the method/class/interface and I will gladly start from there. TIA

推荐答案

PropertyPlaceholderConfigurer具有属性"属性,该属性可以指向检索数据库值的对象.在此处查看示例: http://pure- essential.net/2011/02/10/spring-loading-properties-from-database-with-a-twist/

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/

此外,您还要在从数据库加载属性的Bean上将"ignoreUnresolvablePlaceholders"设置为true.这样,您可以添加另一个PropertyPlaceholderConfigurer作为后备,以提供数据库中找不到的属性.

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.

这篇关于PropertyPlaceholderConfigurer查找数据库值并将属性文件用作后备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆