1.先将配置文件放到如下:<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <!--Spring配置声明--> <sectionGroup name="spring"> <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" /> <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" /> <section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core" /> </sectionGroup> </configSections> <connectionStrings> <!--批量数据上传--> <add name="ConnStr" connectionString="server=.;uid=sa;pwd=123;database=spt;"/> </connectionStrings> <!--Spring配置声明--> <spring> <parsers> <parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data" /> <parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data" /> </parsers> <context> <!--<resource uri="~/Configs/CommonDao.xml" />--> <resource uri="file://~/Configs/CommonDao.xml" /> <resource uri="~/Configs/UserDao.xml" /> <resource uri="~/Configs/UserService.xml" /> <resource uri="~/Configs/Form.xml" /> </context> </spring> <appSettings> </appSettings> </configuration>
对于配置中的外接的xml文件,如上面所示的:<resource uri="file://~/Configs/CommonDao.xml" /> 必须将这个xml文件的属性:输出到输出目录设置为始终复制,因为~代表的是项目生成后exe所在的目录。不如出现错误同http://forum.springframework.net/archive/index.php/t-2929.html
2.下面写下我的commonDao.xml
<?xml version="1.0" encoding="utf-8" ?> <objects xmlns="http://www.springframework.net" xmlns:tx="http://www.springframework.net/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:db="http://www.springframework.net/database"> <!-- Database and NHibernate Configuration --> <db:provider id="DbProvider" provider="SqlServer-2.0" connectionString="server=.;uid=sa;pwd=123;database=spt;"/> <object id="NHibernateSessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate12"> <property name="DbProvider" ref="DbProvider"/> <property name="MappingAssemblies"> <list> <value>Hksj.CommonApp.DaoHibernate</value> </list> </property> <property name="HibernateProperties"> <dictionary> <entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" /> <entry key="hibernate.dialect" value="NHibernate.Dialect.MsSql2005Dialect" /> <entry key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" /> <!--<entry key="show_sql" value="true" />--> </dictionary> </property> </object> <object id="HibernateTransactionManager" type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate12"> <property name="DbProvider" ref="DbProvider"/> <property name="SessionFactory" ref="NHibernateSessionFactory"/> </object> <object id="HibernateTemplate" type="Spring.Data.NHibernate.HibernateTemplate"> <property name="SessionFactory" ref="NHibernateSessionFactory" /> <property name="TemplateFlushMode" value="Auto" /> <property name="CacheQueries" value="true" /> </object> </objects>
其中又报错:session不能create
后来发现:<property name="MappingAssemblies">
<list>
<value>Hksj.CommonApp.DaoHibernate< /value>
</list>
</property>配置的加粗部分是类的映射文件所在项目集的名称,在右击项目属性里面拷贝出来,我的有点变化,所有老是报错。
配置好了,错误怎么查看,一定要点开里面innerexception
如下图所示:
3.类映射文件的属性一定设置为嵌入资源
时间: 2024-10-31 05:21:20