我是.Net的新手。我必须将我的应用程序从.Net 3.5升级到.Net 4.5。这个应用程序使用spring.net和nHibernate。我在执行以下命令的同时在应用程序的第一页上获得空引用错误,因为我引用了PersonDao并且它未初始化。我的问题是对象PersonDao应该基于下面提到的webconfig和Dao文件进行初始化,但是不想知道相同的原因。
_personDao = (IPersonDao)this.ApplicationContext.GetObject("PersonDao");
我保持代码相同,作为升级的一部分我刚刚修改了web配置文件并升级了所使用的spring.net和nhibernate dll。我已尝试在Web配置文件以及spring.net和nhiberbate版本中进行各种排列和组合,但没有任何成功。以下是Web配置文件
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core"/>
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.web"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
</sectionGroup>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
<section name="databaseSettings" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</configSections>
<system.web.extensions>
<scripting>
<webServices>
<authenticationService enabled="true" requireSSL="true"/>
</webServices>
</scripting>
</system.web.extensions>
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
<arg key="configType" value="INLINE"/>
<arg key="configFile" value="~/Config/Log4Net.xml"/>
</factoryAdapter>
</logging>
</common>
<log4net>
<appender name="NHibernateFileLog" type="log4net.Appender.RollingFileAppender">
<file value="Logs/nhibernate.txt"/>
<appendToFile value="true"/>
<rollingStyle value="Size"/>
<maxSizeRollBackups value="10"/>
<maximumFileSize value="100MB"/>
<staticLogFileName value="true"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<appender name="GeneralLog" type="log4net.Appender.RollingFileAppender">
<file value="Logs/general.txt"/>
<appendToFile value="true"/>
<maximumFileSize value="100MB"/>
<rollingStyle value="Size"/>
<maxSizeRollBackups value="5"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<root>
<level value="ERROR"/>
<appender-ref ref="GeneralLog"/>
</root>
<logger name="SSA.Core" additivity="false">
<level value="ERROR"/>
<appender-ref ref="NHibernateFileLog"/>
</logger>
<logger name="NHibernate" additivity="false">
<level value="ERROR"/>
<appender-ref ref="NHibernateFileLog"/>
</logger>
</log4net>
<spring>
<parsers>
<parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data"/>
<parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data"/>
</parsers>
<context>
<resource uri="config://spring/objects"/>
<resource uri="~/Config/Web.xml"/>
<resource uri="~/Config/Dao.xml"/>
<resource uri="~/Config/Services.xml"/>
</context>
</spring>
<appSettings>
<add key="DEFAULT_CLIENT_ID" value="1"/>
<add key="Spring.Data.NHibernate.Support.OpenSessionInViewModule.SessionFactoryObjectName" value="SessionFactory"/>
<add key="hibernate.show_sql" value="true"/>
<add key="hibernate.connection.provider" value ="NHibernate.Connection.DriverConnectionProvider"/>
</appSettings>
<connectionStrings/>
<system.web>
<xhtmlConformance mode="Transitional"/>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
<httpHandlers>
<add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
<add verb="*" path="ContextMonitor.ashx" type="Spring.Web.Support.ContextMonitor, Spring.Web" validate="true"/>
<add verb="*" path="*.asmx" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
<remove verb="*" path="*.asmx"/>
</httpHandlers>
<httpModules>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
<add name="OpenSessionInView" type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate32"/>
</httpModules>
<httpRuntime maxRequestLength="1048576" executionTimeout="50000"/>
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<authentication mode="Forms">
<forms name=".SSACOOKIE" loginUrl="~/Web/Login.aspx" />
</authentication>
<authorization>
<deny users="?"/>
</authorization>
<customErrors mode="Off" defaultRedirect="~/Web/Error.aspx">
</customErrors>
<pages theme="Company" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<controls>
<add tagPrefix="ajax" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagPrefix="ajaxtools" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit"/>
<add tagPrefix="spring" namespace="Spring.Web.UI.Controls" assembly="Spring.Web"/>
</controls>
</pages>
</system.web>
<databaseSettings>
<add key="db.server" value="*********"/>
<add key="db.user" value="*********"/>
<add key="db.password" value="*******"/>
<add key="db.schema" value="**********"/>
</databaseSettings>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<!--<modules>
<add name ="Spring" type ="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</modules>
<handlers>
<add name="SpringPageHandler" verb="*" path="*.aspx" type ="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
<add name="SpringContextMonitor" verb="*" path ="ContextMonitor.ashx" type ="Spring.Web.Support.ContextMonitor, Spring.Web"/>
</handlers>-->
</system.webServer>
<runtime>
<assemblyBinding appliesTo="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Spring.Core" publicKeyToken="65E474D141E25E07" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.3.2.40943" newVersion="1.3.2.40943"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Spring.Aop" publicKeyToken="65E474D141E25E07" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.3.2.40943" newVersion="1.3.2.40943"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Spring.Data" publicKeyToken="65E474D141E25E07" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.3.2.40943" newVersion="1.3.2.40943"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:db="http://www.springframework.net/database"
xmlns:tx="http://www.springframework.net/tx">
<description>
The SSA object definitions for the Data Access Objects.
</description>
<object type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
<property name="ConfigSections" value="databaseSettings"/>
</object>
<!-- Database and NHibernate Configuration -->
<db:provider id="DbProvider"
provider="SqlServer-2.0"
connectionString="Integrated Security=false;Server=${db.server};User ID=${db.user};PWD=${db.password};initial catalog=${db.schema};FailIfMissing=True;"/>
<object id="SessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate32">
<property name="DbProvider" ref="DbProvider"/>
<property name="MappingAssemblies">
<list>
<value>SSA.Core</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<entry key="hibernate.default_schema" value="*****"/>
<entry key="hibernate.dialect" value="NHibernate.Dialect.MsSql2008Dialect"/>
<entry key="hibernate.connection.isolation" value="ReadUncommitted"/>
<entry key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
</dictionary>
</property>
<property name="ExposeTransactionAwareSessionFactory" value="true" />
</object>
<tx:attribute-driven />
<object id="transactionManager" type="Spring.Data.TxScopeTransactionManager, Spring.Data.NHibernate32">
<property name="DbProvider" ref="DbProvider"/>
<property name="SessionFactory" ref="SessionFactory"/>
<property name="NestedTransactionsAllowed" value="true"/>
</object>
<!-- Exception translation object post processor --><!--
<object type="Spring.Dao.Attributes.PersistenceExceptionTranslationPostProcessor, Spring.Data"/>-->
<object id="HibernateTemplate" type="Spring.Data.NHibernate.Generic.HibernateTemplate">
<property name="SessionFactory" ref="SessionFactory" />
<property name="TemplateFlushMode" value="Auto" />
<property name="CacheQueries" value="true" />
</object>
<!-- Data Access Objects -->
<object id="ClientDao" type="SSA.Core.Dao.NHibernate.ClientDao, SSA.Core">
<property name="HibernateTemplate" ref="HibernateTemplate"/>
</object>
<object id="ApplicationDao" type="SSA.Core.Dao.NHibernate.ApplicationDao, SSA.Core">
<property name="HibernateTemplate" ref="HibernateTemplate"/>
</object>
<object id="ApplicationUserDao" type="SSA.Core.Dao.NHibernate.ApplicationUserDao, SSA.Core">
<property name="HibernateTemplate" ref="HibernateTemplate"/>
</object>
<object id="PersonDao" type="SSA.Core.Dao.NHibernate.PersonDao, SSA.Core">
<property name="HibernateTemplate" ref="HibernateTemplate"/>
</object>
.
.
.
.
<object id="CaseDao" type="SSA.Core.Dao.NHibernate.CaseDao, SSA.Core">
<property name="HibernateTemplate" ref="HibernateTemplate"/>
</object>
</objects>
</Dao.XML>
答案 0 :(得分:0)
从IIS迁移时, 'httpHandlers '和 'httpModules' 组件无法正常工作6.0'到'IIS 7.0管道模式 - 集成'导致问题。