我正在尝试将项目从Spring.Net 1.3.2,NHibernate 3.2升级到Spring.Net 2,NHibernate 4。
我收到错误“无法从字符串值'Spring.Data.NHibernate.LocalSessionFactoryObject,Spring.Data.NHibernate'加载类型。”当我试图跑步时。
我的日志显示:
System.Configuration.ConfigurationErrorsException: Error creating context 'spring.root': Could not load type from string value 'Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate'. ---> Spring.Objects.Factory.ObjectCreationException: Error thrown by a dependency of object 'transactionAdvisor' defined in 'file [C:\Users\...\Project.Web\Config\transaction.aop.xml] line 7' : Initialization of object failed : Cannot resolve type [Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate] for object with name 'transactionManager' defined in file [C:\Users\...\Project.Web\Config\hibernate.cfg.xml] line 45
while resolving 'TransactionInterceptor' to 'transactionInterceptor' defined in 'file [C:\Users\...\Project.Web\Config\transaction.aop.xml] line 12' ---> Spring.Core.CannotLoadObjectTypeException: Cannot resolve type [Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate] for object with name 'transactionManager' defined in file [C:\Users\...\Project.Web\Config\hibernate.cfg.xml] line 45 ---> System.TypeLoadException: Could not load type from string value 'Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate'.
at Spring.Core.TypeResolution.TypeResolver.Resolve(String typeName) in c:\_prj\spring-net\src\Spring\Spring.Core\Core\TypeResolution\TypeResolver.cs:line 81
如果我只是打开一个cs文件并创建一个Spring.Data.NHibernate.LocalSessionFactoryObject,它看起来很好,而且命名空间是正确的。 由于版本更改,我确实更改了引用。这就是我现在所拥有的:
transaction.aop.xml
<object id="transactionAdvisor" type="Spring.Transaction.Interceptor.TransactionAttributeSourceAdvisor, Spring.Data">
<property name="TransactionInterceptor" ref="transactionInterceptor"/>
</object>
<!-- Transaction Interceptor -->
<object id="transactionInterceptor" type="Spring.Transaction.Interceptor.TransactionInterceptor, Spring.Data">
<property name="TransactionManager" ref="transactionManager"/>
<property name="TransactionAttributeSource" ref="attributeTransactionAttributeSource"/>
</object>
<object id="attributeTransactionAttributeSource" type="Spring.Transaction.Interceptor.AttributesTransactionAttributeSource, Spring.Data">
</object>
的hibernate.cfg.xml
<object id="placeholder_db_settings" type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
<property name="ConfigSections" value="databaseSettings,appSettings,emailSettings"/>
</object>
<db:provider id="DbProvider" provider="SqlServer-2.0" connectionString="Data Source=${db.datasource};Database=${db.database};User ID=${db.user};Password=${db.password};Connect Timeout=${db.connectTimeout}"/>
<object id="hibernateSessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate">
<property name="DbProvider" ref="DbProvider"/>
<property name="MappingAssemblies">
<list>
<value>IBB.BusinessNet.Services</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key-ref="connection.provider" value-ref="NHibernate.Connection.DriverConnectionProvider"/>
<entry key-ref="show_sql" value-ref="false"/>
<entry key-ref="dialect" value-ref="NHibernate.Dialect.MsSql2008Dialect"/>
<entry key-ref="connection.driver_class" value-ref="NHibernate.Driver.SqlClientDriver"/>
<entry key-ref="connection.pool_size" value-ref="10"/>
<entry key-ref="query.substitutions" value-ref="true 1, false 0, yes 'Y', no 'N'"/>
<entry key-ref="use_outer_join" value-ref="true"/>
<entry key-ref="command_timeout" value-ref="840" />
<entry key-ref="cache.provider_class" value-ref="NHibernate.Caches.SysCache2.SysCacheProvider,NHibernate.Caches.SysCache2" />
</dictionary>
</property>
<property name="ExposeTransactionAwareSessionFactory" value="true" />
</object>
<object id="transactionManager" type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate">
<property name="DbProvider" ref="DbProvider"/>
<property name="SessionFactory" ref="hibernateSessionFactory"/>
</object>
<object id="MyHibernateTemplate" type="Spring.Data.NHibernate.Generic.HibernateTemplate">
<property name="SessionFactory" ref="hibernateSessionFactory" />
<property name="TemplateFlushMode" value="Auto" />
<property name="AllowCreate" value="true" />
<property name="CacheQueries" value="true" />
</object>
<object id="HibernateTemplate" type="Spring.Data.NHibernate.HibernateTemplate">
<property name="SessionFactory" ref="hibernateSessionFactory" />
<property name="TemplateFlushMode" value="Auto" />
<property name="AllowCreate" value="true" />
<property name="CacheQueries" value="true" />
</object>
当然,所有东西都经过消毒和修剪以减少空间。我没有更改映射hbm文件,因为我没有发现任何我应该说的内容。
我将Spring登录到DEBUG,修复了一些问题。将NHibernate更改为DEBUG不会添加任何日志记录,因为它没有那么远。春天加载其他一切都很好。 hibernate.cfg.xml输出DEBUG消息,其中包含“忽略对象X的对象类加载失败”所有这些消息 “无法从字符串值加载类型”。 第一个错误是“GetObjectInternal:错误获取对象transactionManager”。
我把头撞在墙上几个小时试图找出原因。我知道有些人比我更了解这些东西,可以指出我正确的方向,所以这是我的求助。
答案 0 :(得分:1)
Bah,我一直想要使用命名空间而不是程序集名称。 hibernate.cfg.xml中的2行必须是DLL的名称。
<object id="hibernateSessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate4">
...
<object id="transactionManager" type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate4">