在尝试将我的项目从.NET 3.5转换为.NET 4时,我遇到了Spring.net最棘手的问题。
让我总结一下我们的架构: 项目A(不在我的控制下)有一个Sprint.Net配置引用一个设置(configurationProvider.url),如下所示:
<constructor-arg name="Url" value="${configurationProvider.url}" />
项目B(我的项目,在我的控制下)有另一个配置文件,其中包含此设置的值:
<configuration>
<Environment>
<add key="Dashboard.Environment" value="UAT" />
<add key="configurationProvider.url" value="http://something/ConfigurationProvider.asmx"/>
<add key="pkicheck.url" value="http://something/webservices/pkicheck.asmx"/>
<add key="sso.url" value="http://something/webservices/ssoclient.asmx"/>
</Environment>
</configuration>
当Project B是.NET 3.5时,一切正常。 将此项目转换为.NET 4(这是唯一的更改)时,整个事情开始失败,并且它给了我这个例外:
Could not resolve placeholder 'configurationProvider.url'
显然没有在ProjectB配置文件中找到配置设置,尽管此文件存在且包含值。 什么可以在3.5和4之间改变?
完全例外:
<ConfigurationErrorsException d1p1:type="ConfigurationErrorsException">
<ClassName>System.Configuration.ConfigurationErrorsException</ClassName>
<Message>Error creating context 'spring.root': Error registering object with name 'configurationProvider' defined in 'assembly [ProjectA.Core, Version=0.0.0.88, Culture=neutral, PublicKeyToken=1b28b51fb20f454e], resource [ProjectA.Core.Framework.config] line 111' : Could not resolve placeholder 'configurationProvider.url'.</Message>
<Data d1p1:type="IDictionary"/>
<InnerException d1p1:type="Exception">
<ClassName>Spring.Objects.Factory.ObjectDefinitionStoreException</ClassName>
<Message>Error registering object with name 'configurationProvider' defined in 'assembly [ProjectA.Core, Version=0.0.0.88, Culture=neutral, PublicKeyToken=1b28b51fb20f454e], resource [ProjectA.Core.Framework.config] line 111' : Could not resolve placeholder 'configurationProvider.url'.</Message>
<Data d1p1:type="IDictionary"/>
<InnerException d1p1:type="Exception"/>
<HelpURL/>
<StackTraceString> at Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer.ProcessProperties(IConfigurableListableObjectFactory factory, NameValueCollection props) at Spring.Objects.Factory.Config.PropertyResourceConfigurer.PostProcessObjectFactory(IConfigurableListableObjectFactory factory) at Spring.Context.Support.AbstractApplicationContext.ProcessObjectFactoryPostProcessors(IList objectFactoryPostProcessors) at Spring.Context.Support.AbstractApplicationContext.InvokeObjectFactoryPostProcessors() at Spring.Context.Support.AbstractApplicationContext.Refresh() at Spring.Context.Support.XmlApplicationContext..ctor(Boolean refresh, String name, Boolean caseSensitive, IApplicationContext parentContext, String[] configurationLocations) at Spring.Context.Support.XmlApplicationContext..ctor(String name, Boolean caseSensitive, String[] configurationLocations) at _dynamic_Spring.Context.Support.XmlApplicationContext..ctor(Object[] ) at Spring.Reflection.Dynamic.SafeConstructor.Invoke(Object[] arguments) at Spring.Context.Support.ContextHandler.RootContextInstantiator.InvokeContextConstructor(ConstructorInfo ctor) at Spring.Context.Support.ContextHandler.ContextInstantiator.InstantiateContext() at Spring.Context.Support.ContextHandler.InstantiateContext(IApplicationContext parentContext, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources) at Spring.Context.Support.ContextHandler.Create(Object parent, Object configContext, XmlNode section)</StackTraceString>
<RemoteStackTraceString/>
<RemoteStackIndex>0</RemoteStackIndex>
<ExceptionMethod>8 ProcessProperties Spring.Core, Version=1.3.0.20349, Culture=neutral, PublicKeyToken=65e474d141e25e07 Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer Void ProcessProperties(Spring.Objects.Factory.Config.IConfigurableListableObjectFactory, System.Collections.Specialized.NameValueCollection)</ExceptionMethod>
<HResult>-2146232832</HResult>
<Source>Spring.Core</Source>
<WatsonBuckets d1p1:type="System.Byte"d1p1:includeArrayAttribute="true"/>
<_resourceDescription>assembly [ProjectA.Core, Version=0.0.0.88, Culture=neutral, PublicKeyToken=1b28b51fb20f454e], resource [ProjectA.Core.Framework.config] line 111</_resourceDescription>
<_objectName>configurationProvider</_objectName>
</InnerException>
<HelpURL/>
<StackTraceString> at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at Spring.Util.ConfigurationUtils.GetSection(String sectionName) at Spring.Context.Support.ContextRegistry.InitializeContextIfNeeded() at Spring.Context.Support.ContextRegistry.GetContext() at ProjectA.Core.Controller.Initialise(String flavour) in d:\TeamCity8100\buildAgent\work\850180d7b576030f\Code\Src\ProjectA\Framework\Core\Controller.cs:line 238</StackTraceString>
<RemoteStackTraceString/>
<RemoteStackIndex>0</RemoteStackIndex>
<ExceptionMethod>8 EvaluateOne System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Configuration.BaseConfigurationRecord System.Object EvaluateOne(System.String[], System.Configuration.SectionInput, Boolean, System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object)</ExceptionMethod>
<HResult>-2146232062</HResult>
<Source>System.Configuration</Source>
<WatsonBuckets d1p1:type="System.Byte"d1p1:includeArrayAttribute="true"/>
<filename d1p1:type="Object"/>
<line>0</line>
<firstFilename d1p1:type="Object"/>
<firstLine>0</firstLine>
<count>0</count>
</ConfigurationErrorsException>
答案 0 :(得分:1)
我最终发现了这个问题。 我们在配置中使用PropertyPlaceholderConfigurer,我们从不设置“Order”属性。因此Spring在Order上“排序”,但由于Order总是等于int.Max,因此订单输出是非确定性的。
将Order添加到配置文件中修复它。