目前在我的 app.config 中,我已经创建了一个单独的部分用于弹簧依赖项解析,如下所示,并且工作正常。
<ConfigurationSettings>
<add key="urlprovider" value="Proxy.DependencyProperty.BaseUrl, Proxy"/>
<add key="wstimeoutprovider" value="Proxy.DependencyProperty.WebServiceTimeout, Proxy"/>
<add key="powerreconurlprovider" value="Proxy.DependencyProperty.PowerReconUrl, Proxy"/>
<add key="credentialprovider" value="DependencyProperty.ServerCredential, Proxy" />
</ConfigurationSettings>
但是我想通过代码提供这个。所以我创建了这样的配置类
[Configuration]
public class ProxyConfiguration
{
[Definition]
public virtual KeyValueConfigurationCollection ConfigurationSettings()
{
KeyValueConfigurationCollection collection = new KeyValueConfigurationCollection();
collection.Add("urlprovider", "Proxy.DependencyProperty.BaseUrl,Proxy");
collection.Add("wstimeoutprovider","Proxy.DependencyProperty.BaseUrl,Proxy");
collection.Add("powerreconurlprovider","Proxy.DependencyProperty.BaseUrl,Proxy");
collection.Add("credentialprovider","Proxy.DependencyProperty.BaseUrl,Proxy");
return collection;
}
}
然后像下面这样创建 CodeConfigurationContext
var ctx = new CodeConfigApplicationContext();
ctx.ScanWithAssemblyFilter(assy => (assy.FullName.Contains("Test")));
ctx.Refresh();
但是,我仍然从 Spring.root 收到 ConfigurationErrorsException 未被代码处理的异常。创建上下文“spring.root”时出错:使用名称注册对象时出错...无法解析占位符“urlprovider”。如何解决这个问题?