我想使用兩個屬性佔位符配置器,其中一個用於檢索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