Spring.Net + ASP:页面实例化两次

时间:2014-02-16 17:07:42

标签: asp.net dependency-injection spring.net

我的项目基于 Spring Northwind 示例,但我一定做错了。我正在构建一个DAO对象并将其注入到ASP页面中,但是我看到同一页面由 IIS 构建,没有 Spring的好处

页面 WorkFlowDetail.aspx 继承自名为 BasePage1 的基类。 BasePage1 有一个DAO的公共属性,给我们这样的东西:

BasePage1.vb

Public Class BasePage1
    Inherits System.Web.UI.Page

    Private _wfdao As IWfDao
    Public Property wfDao As IWfDao
        Get
            Return _wfdao
        End Get
        Set(value As IWfDao)
            _wfdao = value
        End Set
    End Property
End Class

WorkFlowDetail.aspx.vb

Public Class WorkFlowDetail
    Inherits BasePage1
End Class

Web.xml中

  <object name="BasePage1">
    <property name="wfDao" ref="wfDao" />
  </object>

  <object type="WorkFlowDetail.aspx" parent="BasePage1">
  </object>

的Web.config

<configuration>
  <configSections>
    <sectionGroup name="spring">
      <section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web" />
      <section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core" />
    </sectionGroup>
  </configSections>

  <spring>
    <parsers>
      <parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data" />
      <parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data" />
    </parsers>
    <context annotation-config="">
      <resource uri="~/Config/Aspects.xml" />
      <resource uri="~/Web.xml" />
    </context>
  </spring>

  <system.web>
    <httpHandlers>
      <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
      <add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
    </httpHandlers>
    <httpModules>
      <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
    </httpModules>
  </system.web>

  <system.webServer>
    <handlers>
      <add name="SpringPageHandler" verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
      <add name="SpringWebServiceHandler" verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web" />
      <add name="SpringContextMonitor" verb="*" path="ContextMonitor.ashx" type="Spring.Web.Support.ContextMonitor, Spring.Web"/>
      <add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" />
    </handlers>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web" />
      <add name="OpenSessionInView" type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate32" />
    </modules>
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>

  <appSettings>
    <add key="Spring.Data.NHibernate.Support.OpenSessionInViewModule.SessionFactoryObjectName" value="NHibernateSessionFactory" />
  </appSettings>

</configuration>

[显然我遗漏了许多我认为不相关的东西。]

设置几个战略断点我发现 WorkFlowDetail.aspx 首先由 Spring 构造,并注入DAO对象。它在调试器的监视列表中显示为“(ASP.workflowdetail_aspx)”,堆栈如下所示:

[External Code] 
Spring.Web.dll!Spring.Util.VirtualEnvironment.HttpRuntimeEnvironment.CreateInstanceFromVirtualPath(string virtualPath, System.Type requiredBaseType) Line 409 + 0x12 bytes  C#
Spring.Web.dll!Spring.Util.VirtualEnvironment.CreateInstanceFromVirtualPath(string virtualPath, System.Type requiredBaseType) Line 515 + 0x44 bytes C#
Spring.Web.dll!Spring.Objects.Factory.Support.WebObjectUtils.CreateHandler(string pageUrl) Line 156 + 0x20 bytes    C#
Spring.Web.dll!Spring.Objects.Factory.Support.WebObjectUtils.CreatePageInstance(string pageUrl) Line 105 + 0xc bytes    C#
Spring.Web.dll!Spring.Objects.Factory.Support.WebInstantiationStrategy.Instantiate(Spring.Objects.Factory.Support.RootObjectDefinition definition, string name, Spring.Objects.Factory.IObjectFactory factory) Line 76 + 0x50 bytes C#
Spring.Core.dll!Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(string objectName, Spring.Objects.Factory.Support.RootObjectDefinition definition) Line 1036 + 0x43 bytes C#
Spring.Core.dll!Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.CreateObjectInstance(string objectName, Spring.Objects.Factory.Support.RootObjectDefinition objectDefinition, object[] arguments) Line 1000 + 0x2a bytes    C#
Spring.Core.dll!Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(string name, Spring.Objects.Factory.Support.RootObjectDefinition definition, object[] arguments, bool allowEagerCaching, bool suppressConfigure) Line 904 + 0x21 bytes    C#
Spring.Core.dll!Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectInternal(string name, System.Type requiredType, object[] arguments, bool suppressConfigure) Line 2037 + 0x3a bytes    C#
Spring.Core.dll!Spring.Objects.Factory.Support.AbstractObjectFactory.CreateObject(string name, System.Type requiredType, object[] arguments) Line 1817 + 0x1e bytes C#
Spring.Core.dll!Spring.Context.Support.AbstractApplicationContext.CreateObject(string name, System.Type requiredType, object[] arguments) Line 1495 + 0x4d bytes    C#
Spring.Web.dll!Spring.Web.Support.PageHandlerFactory.CreateHandlerInstance(Spring.Context.IConfigurableApplicationContext appContext, System.Web.HttpContext context, string requestType, string rawUrl, string physicalPath) Line 108 + 0x85 bytes C#
Spring.Web.dll!Spring.Web.Support.AbstractHandlerFactory.GetHandler(System.Web.HttpContext context, string requestType, string url, string physicalPath) Line 208 + 0x43 bytes  C#
Spring.Web.dll!Spring.Web.Support.PageHandlerFactory.GetHandler(System.Web.HttpContext context, string requestType, string url, string physicalPath) Line 77 + 0x23 bytes   C#
[External Code] 

然后再次调用构造函数。这次对象在调试器的监视列表中显示为“scheduleSite.WorkFlowDetail”,而堆栈只显示

[External Code] 

请告诉我这个配置我做错了什么。我已经尝试将所有 BasePage1 Web.xml 中删除,结果相同。

更新

首先,页面构建的次数不止两次;我只想过两次,因为它第二次抛出一个异常,但我发现如果我经过那里,我会再次击中构造函数3-4次。

其次,我怀疑我的问题源于 Web.config 的错误配置。我注意到 Northwind 只有&lt; system.web &gt;部分,而我的应用程序(在我进入项目之前设置)同时具有&lt; system.web &gt;和&lt; system.webServer &gt;。 Northwind 定位 .NET 3.5 ,而我们的目标是集成< 4.0 IIS7.0 / strong>模式。我现在正在研究如何配置它,但仍然会感谢帮助。

0 个答案:

没有答案