我想使用两个属性占位符配置器,其中一个用于检索base64解码值。我遇到的问题是只有其中一个将属性加载到名称/值集合中。哪一个依赖于我将它们放置在XML中的顺序(并且在切换它们时设置第一个忽略不可解析)。Spring.NET使用多个PropertyPlaceholderConfigurers不起作用
这里的配置是什么样子:
<object id="propertyConfigurer" type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>file://~Database.config</value>
</list>
</property>
<property name="configSections">
<list>
<value>database</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</object>
<object id="encodedPropertyConfigurer" type="MyProject.Config.EncodedPropertyConfigurer">
<property name="locations">
<list>
<value>file://~Database_auth.config</value>
</list>
</property>
<property name="configSections">
<list>
<value>database_auth</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="false" />
</object>
我延长PropertyPlaceholderConfigurer,覆盖像这样的虚方法:
public class EncodedPropertyConfigurer : PropertyPlaceholderConfigurer
{
protected override string ResolvePlaceholder(string placeholder, System.Collections.Specialized.NameValueCollection props)
{
return System.Text.Encoding.ASCII.GetString(Convert.FromBase64String(base.ResolvePlaceholder(placeholder, props)));
}
}
再次,根据我把它们在Web.config的顺序,只有一个文件被加载到Name/Value集合中。作为粘贴,它将使用encodedPropertyConfigurer(例如,我会在集合中看到“用户名”和“密码”,但不是连接字符串。如果我翻转该命令,我会看到“connectionString”,但不是用户名或密码。 我做错了什么?该文档说支持多个PropertyPlaceholderConfigurer,并且只需要注意ignoreUnresolvable设置。 请注意,我测试使用这两个实例作为Spring PropertyPlaceholderConfigurer(而不是我的扩展类)和SAME行为发生 - 只有一个被加载到列表中。
为什么不理想? – Najera