设置:Spring.Objects.Factory.ObjectDefinitionStoreException:注册对象时出错,名称 'NHibernateSessionFactory' 在“程序集”中定义
SetUp : Spring.Objects.Factory.ObjectDefinitionStoreException : Error registering object with name 'NHibernateSessionFactory' defined in 'assembly
当我 运行 进行单元测试时,这是我遇到的错误:
SetUp : Spring.Objects.Factory.ObjectDefinitionStoreException : Error registering object with name 'NHibernateSessionFactory' defined in 'assembly [Eiq.Middleware.Data.DomainRepository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c61376b85e43767], resource [Eiq.Middleware.Data.DomainRepository.Persistence.xml] line 15' : Could not resolve placeholder 'TDM.providerName'.
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.InvokeObjectFactoryPostProcessors(IList objectFactoryPostProcessors, IConfigurableListableObjectFactory objectFactory)
at Spring.Context.Support.AbstractApplicationContext.InvokeObjectFactoryPostProcessors(IConfigurableListableObjectFactory objectFactory)
at Spring.Context.Support.AbstractApplicationContext.Refresh()
at Spring.Context.Support.XmlApplicationContext..ctor(XmlApplicationContextArgs args)
at Spring.Context.Support.XmlApplicationContext..ctor(String[] configurationLocations)
at Spring.Testing.NUnit.AbstractSpringContextTests.LoadContextLocations(String[] locations)
at Spring.Testing.NUnit.AbstractDependencyInjectionSpringContextTests.LoadContextLocations(String[] locations)
at Spring.Testing.NUnit.AbstractSpringContextTests.GetContext(Object key)
at Spring.Testing.NUnit.AbstractDependencyInjectionSpringContextTests.SetUp()
有没有什么方法可以通过在我的单元测试 app.config 中设置一些东西来让它以某种方式传递 "TDM.providerName" 的值?这是我试过的,但没有帮助,其中测试项目的名称是MiddlewareTests,默认命名空间是Eiq.Middleware.SmokeTest:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="databaseProperties" type="System.Configuration.NameValueSectionHandler, System" />
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" restartOnExternalChanges="true" />
</sectionGroup>
</configSections>
<appSettings>
<add key="DefaultUserName" value="tdmuser" />
<!-- Well Query Limit -->
<add key="WellQueryLimit" value="50000" />
<add key="TDM.providerName" value="SqlServer-2.0"/>
</appSettings>
<spring>
<parsers>
<parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data" />
<parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data" />
<parser type="Spring.Aop.Config.AopNamespaceParser, Spring.Aop" />
</parsers>
<context>
<resource uri="assembly://MiddlewareTests/Eiq.Middleware.SmokeTest/Persistence.xml" />
<resource uri="assembly://MiddlewareTests/TEiq.Middleware.SmokeTest/Repositories.xml" />
<resource uri="assembly://MiddlewareTests/Eiq.Middleware.SmokeTest/Services.xml" />
<resource uri="config://spring/objects" />
</context>
<objects configSource="config\spring.config" />
</spring>
</configuration>
或者,我如何让应用程序指向我修改过的 Persistence.xml、Repositories.xml 和 Services.xml 文件的副本,以便在我的单元测试中直接进行测试项目?有没有人有任何其他建议?
为了解决上述问题,执行了几个步骤,但我不确定具体是哪个步骤解决了问题:
- 在我的测试项目中添加了对 NHibernate.Validator、版本=1.3.1.4000 和 NHibernate.Caches.SysCache、版本 3.1.0.4000
的引用
- 在我的测试项目中添加了参考 log4net,Version=1.2.10.0 以打印出更多诊断信息
- 在我的测试项目中添加了对 System.Configuration、System.Web.ApplicationServices 和 System.Web.Extensions 的引用
- 从我的测试项目中删除了对 Spring.Core 和 Spring.Data 的引用。
此外,将我的测试项目中的 App.config 文件更新为以下内容,其中关键部分是与休眠配置相关的部分:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="databaseProperties" type="System.Configuration.NameValueSectionHandler, System" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" restartOnExternalChanges="true" />
</sectionGroup>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
<section name="nhv-configuration" type="NHibernate.Validator.Cfg.ConfigurationSectionHandler, NHibernate.Validator" requirePermission="false" />
<section name="auditConfig" type="Eiq.Middleware.Common.Config.AuditConfigSectionHandler, Eiq.Middleware.Common" restartOnExternalChanges="true" />
<section name="coordSys" type="Eiq.Middleware.Common.Config.CoordSysSectionHandler, Eiq.Middleware.Common" restartOnExternalChanges="true" />
</configSections>
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message%newline" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="ConsoleAppender" />
</root>
</log4net>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=localhost;Initial Catalog=ENERGYIQ;User Id=svc_tdm;Password=svc_tdm;
</property>
<mapping assembly="TdmTests" />
</session-factory>
<nhv-configuration xmlns="urn:nhv-configuration-1.0">
<shared_engine_provider class="NHibernate.Validator.Event.NHibernateSharedEngineProvider, NHibernate.Validator" />
</nhv-configuration>
<auditConfig configSource="Config\audit.config" />
<connectionStrings configSource="config\connectionStrings.config" />
<spring>
<parsers>
<parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data" />
<parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data" />
<parser type="Spring.Aop.Config.AopNamespaceParser, Spring.Aop" />
</parsers>
<context>
<resource uri="assembly://TdmTests/TdmTests/Persistence.xml" />
<resource uri="assembly://TdmTests/TdmTests/Repositories.xml" />
<resource uri="assembly://TdmTests/TdmTests/Services.xml" />
<resource uri="config://spring/objects" />
</context>
<objects configSource="config\spring.config" />
</spring>
<appSettings>
<add key="DefaultUserName" value="tdmuser" />
<!-- Well Query Limit -->
<add key="WellQueryLimit" value="50000" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
</configuration>
HTH.
当我 运行 进行单元测试时,这是我遇到的错误:
SetUp : Spring.Objects.Factory.ObjectDefinitionStoreException : Error registering object with name 'NHibernateSessionFactory' defined in 'assembly [Eiq.Middleware.Data.DomainRepository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c61376b85e43767], resource [Eiq.Middleware.Data.DomainRepository.Persistence.xml] line 15' : Could not resolve placeholder 'TDM.providerName'.
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.InvokeObjectFactoryPostProcessors(IList objectFactoryPostProcessors, IConfigurableListableObjectFactory objectFactory)
at Spring.Context.Support.AbstractApplicationContext.InvokeObjectFactoryPostProcessors(IConfigurableListableObjectFactory objectFactory)
at Spring.Context.Support.AbstractApplicationContext.Refresh()
at Spring.Context.Support.XmlApplicationContext..ctor(XmlApplicationContextArgs args)
at Spring.Context.Support.XmlApplicationContext..ctor(String[] configurationLocations)
at Spring.Testing.NUnit.AbstractSpringContextTests.LoadContextLocations(String[] locations)
at Spring.Testing.NUnit.AbstractDependencyInjectionSpringContextTests.LoadContextLocations(String[] locations)
at Spring.Testing.NUnit.AbstractSpringContextTests.GetContext(Object key)
at Spring.Testing.NUnit.AbstractDependencyInjectionSpringContextTests.SetUp()
有没有什么方法可以通过在我的单元测试 app.config 中设置一些东西来让它以某种方式传递 "TDM.providerName" 的值?这是我试过的,但没有帮助,其中测试项目的名称是MiddlewareTests,默认命名空间是Eiq.Middleware.SmokeTest:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="databaseProperties" type="System.Configuration.NameValueSectionHandler, System" />
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" restartOnExternalChanges="true" />
</sectionGroup>
</configSections>
<appSettings>
<add key="DefaultUserName" value="tdmuser" />
<!-- Well Query Limit -->
<add key="WellQueryLimit" value="50000" />
<add key="TDM.providerName" value="SqlServer-2.0"/>
</appSettings>
<spring>
<parsers>
<parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data" />
<parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data" />
<parser type="Spring.Aop.Config.AopNamespaceParser, Spring.Aop" />
</parsers>
<context>
<resource uri="assembly://MiddlewareTests/Eiq.Middleware.SmokeTest/Persistence.xml" />
<resource uri="assembly://MiddlewareTests/TEiq.Middleware.SmokeTest/Repositories.xml" />
<resource uri="assembly://MiddlewareTests/Eiq.Middleware.SmokeTest/Services.xml" />
<resource uri="config://spring/objects" />
</context>
<objects configSource="config\spring.config" />
</spring>
</configuration>
或者,我如何让应用程序指向我修改过的 Persistence.xml、Repositories.xml 和 Services.xml 文件的副本,以便在我的单元测试中直接进行测试项目?有没有人有任何其他建议?
为了解决上述问题,执行了几个步骤,但我不确定具体是哪个步骤解决了问题:
- 在我的测试项目中添加了对 NHibernate.Validator、版本=1.3.1.4000 和 NHibernate.Caches.SysCache、版本 3.1.0.4000 的引用
- 在我的测试项目中添加了参考 log4net,Version=1.2.10.0 以打印出更多诊断信息
- 在我的测试项目中添加了对 System.Configuration、System.Web.ApplicationServices 和 System.Web.Extensions 的引用
- 从我的测试项目中删除了对 Spring.Core 和 Spring.Data 的引用。
此外,将我的测试项目中的 App.config 文件更新为以下内容,其中关键部分是与休眠配置相关的部分:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="databaseProperties" type="System.Configuration.NameValueSectionHandler, System" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" restartOnExternalChanges="true" />
</sectionGroup>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
<section name="nhv-configuration" type="NHibernate.Validator.Cfg.ConfigurationSectionHandler, NHibernate.Validator" requirePermission="false" />
<section name="auditConfig" type="Eiq.Middleware.Common.Config.AuditConfigSectionHandler, Eiq.Middleware.Common" restartOnExternalChanges="true" />
<section name="coordSys" type="Eiq.Middleware.Common.Config.CoordSysSectionHandler, Eiq.Middleware.Common" restartOnExternalChanges="true" />
</configSections>
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message%newline" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="ConsoleAppender" />
</root>
</log4net>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=localhost;Initial Catalog=ENERGYIQ;User Id=svc_tdm;Password=svc_tdm;
</property>
<mapping assembly="TdmTests" />
</session-factory>
<nhv-configuration xmlns="urn:nhv-configuration-1.0">
<shared_engine_provider class="NHibernate.Validator.Event.NHibernateSharedEngineProvider, NHibernate.Validator" />
</nhv-configuration>
<auditConfig configSource="Config\audit.config" />
<connectionStrings configSource="config\connectionStrings.config" />
<spring>
<parsers>
<parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data" />
<parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data" />
<parser type="Spring.Aop.Config.AopNamespaceParser, Spring.Aop" />
</parsers>
<context>
<resource uri="assembly://TdmTests/TdmTests/Persistence.xml" />
<resource uri="assembly://TdmTests/TdmTests/Repositories.xml" />
<resource uri="assembly://TdmTests/TdmTests/Services.xml" />
<resource uri="config://spring/objects" />
</context>
<objects configSource="config\spring.config" />
</spring>
<appSettings>
<add key="DefaultUserName" value="tdmuser" />
<!-- Well Query Limit -->
<add key="WellQueryLimit" value="50000" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
</configuration>
HTH.