天天看點

Spring.Net在Mvc4.0中應用的說明

案例Demo:http://yunpan.cn/cJ5aZrm7Uybi3 通路密碼 414b

Spring.Net在Mvc4.0中應用的說明

1.引用dll

Spring.Net在Mvc4.0中應用的說明

2.修改Global檔案 (SpringMvcApplication)

Spring.Net在Mvc4.0中應用的說明

3.控制器添加屬性

Spring.Net在Mvc4.0中應用的說明

4.WebConfig配置

<!--必須緊跟着configuration之後-->

  <configSections>

    <sectionGroup name="spring">

      <section name="context" type="Spring.Context.Support.MvcContextHandler, Spring.Web.Mvc4"/>

    </sectionGroup>

  </configSections>

  <!--Spring.Net節點詳細配置-->

  <spring>

    <context>

      <!--配置檔案在網站根目錄下的Config檔案夾下的Spring.xml記得把xml檔案設定成始終複制到輸出目錄-->

      <resource uri="file://~/Config/Spring.xml"/>

    </context>

  </spring>

  <!--Spring.Net節點詳細配置結束-->

Spring.Net在Mvc4.0中應用的說明

5.Spring.xml的配置(記得右鍵屬性設定Spring.xml始終複制到輸入目錄)

<objects xmlns="http://www.springframework.net">

  <!--放容器裡面的所有的節點  type屬性的規範:程式集名稱在内的類型全名,程式集名-->

  <object type="Spring.Net.MVCDemo.Controllers.UserInfoController,Spring.Net.MVCDemo" singleton="false" >

    <!--給UserInfoController注入UserRegInfoService對象-->

    <property name="UserRegInfoService" ref="UserRegInfoService" />

  </object>

  <!--配置Service-->

  <object name="UserRegInfoService" type="Spring.Net.MVCDemo.Service.UserRegInfoService,Spring.Net.MVCDemo.Service" singleton="false" >

</objects>

Spring.Net在Mvc4.0中應用的說明

6.注意此異常資訊

Could not load type from string value 'Spring.Net.MVCDemo.Service.UserRegInfoService,Spring.Net.MVCDemo.Service'.

說明: 執行目前 Web 請求期間,出現未經處理的異常。請檢查堆棧跟蹤資訊,以了解有關該錯誤以及代碼中導緻錯誤的出處的詳細資訊。 

異常詳細資訊: System.TypeLoadException: Could not load

type from string value

'Spring.Net.MVCDemo.Service.UserRegInfoService,Spring.Net.MVCDemo.Service'.

源錯誤: 

執行目前 Web 請求期間生成了未經處理的異常。可以使用下面的異常堆棧跟蹤資訊确定有關異常原因和發生位置的資訊。

堆棧跟蹤: 

[TypeLoadException: Could not load type from string

value

'Spring.Net.MVCDemo.Service.UserRegInfoService,Spring.Net.MVCDemo.Service'.]

Spring.Core.TypeResolution.TypeResolver.Resolve(String typeName) in

f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Core\TypeResolution\TypeResolver.cs:81

Spring.Core.TypeResolution.GenericTypeResolver.Resolve(String typeName)

in

f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Core\TypeResolution\GenericTypeResolver.cs:91

Spring.Core.TypeResolution.CachedTypeResolver.Resolve(String typeName)

in f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Core\TypeResolution\CachedTypeResolver.cs:107

Spring.Core.TypeResolution.TypeResolutionUtils.ResolveType(String

typeName) in

f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Core\TypeResolution\TypeResolutionUtils.cs:101

Spring.Objects.Factory.Support.AbstractObjectDefinition.ResolveObjectType()

f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectDefinition.cs:639

Spring.Objects.Factory.Support.AbstractObjectFactory.ResolveObjectType(RootObjectDefinition

rod, String objectName) in

f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs:1123

[CannotLoadObjectTypeException: Cannot resolve type

[Spring.Net.MVCDemo.Service.UserRegInfoService,Spring.Net.MVCDemo.Service]

for object with name 'UserRegInfoService' defined in file

[C:\Users\DNT\Desktop\Spring.Net.MVCDemo\Spring.Net.MVCDemo\Spring.Net.MVCDemo\Config\Spring.xml]

line 19]

f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs:1127

Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.PredictObjectType(String

objectName, RootObjectDefinition mod) in

f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs:160

Spring.Objects.Factory.Support.DefaultListableObjectFactory.IsFactoryObject(String

objectName, RootObjectDefinition rod) in

f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Objects\Factory\Support\DefaultListableObjectFactory.cs:1079

Spring.Objects.Factory.Support.DefaultListableObjectFactory.DoGetObjectNamesForType(Type

type, Boolean includeNonSingletons, Boolean allowEagerInit) in

f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Objects\Factory\Support\DefaultListableObjectFactory.cs:1011

Spring.Objects.Factory.Support.DefaultListableObjectFactory.DoGetObjectsOfType(Type

type, Boolean includePrototypes, Boolean includeFactoryObjects, IDictionary

resultCollector) in

f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Objects\Factory\Support\DefaultListableObjectFactory.cs:841

Spring.Objects.Factory.Support.DefaultListableObjectFactory.GetObjectsOfType(Type

type, Boolean includePrototypes, Boolean includeFactoryObjects) in

f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Objects\Factory\Support\DefaultListableObjectFactory.cs:835

Spring.Context.Support.AbstractApplicationContext.GetObjectsOfType(Type

f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Context\Support\AbstractApplicationContext.cs:1476

type) in

f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Context\Support\AbstractApplicationContext.cs:1411

Spring.Web.Mvc.SpringMvcDependencyResolver.GetService(Type

serviceType) in f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Web.Mvc4\SpringMvcDependencyResolver.cs:77

System.Web.Mvc.DependencyResolverExtensions.GetService(IDependencyResolver

resolver) +56

System.Web.Mvc.SingleServiceResolver`1.GetValueFromResolver() +43

System.Lazy`1.CreateValue() +416

System.Lazy`1.LazyInitValue() +152

System.Lazy`1.get_Value() +75

System.Web.Mvc.SingleServiceResolver`1.get_Current() +15

System.Web.Mvc.MvcRouteHandler.GetSessionStateBehavior(RequestContext

requestContext) +125

System.Web.Mvc.MvcRouteHandler.GetHttpHandler(RequestContext

requestContext) +33

System.Web.Mvc.MvcRouteHandler.System.Web.Routing.IRouteHandler.GetHttpHandler(RequestContext

requestContext) +10

System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase

context) +9770076

System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(Object

sender, EventArgs e) +82

System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

+136

System.Web.HttpApplication.ExecuteStep(IExecutionStep step,

Boolean& completedSynchronously) +69

版本資訊: Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.34009

 解釋如圖:

Spring.Net在Mvc4.0中應用的說明

樓主已經棄用Spring.NET,推薦使用autofac

作者:毒逆天

出處:https://www.cnblogs.com/dotnetcrazy

打賞:<b>18i4JpL6g54yAPAefdtgqwRrZ43YJwAV5z</b>

本文版權歸作者和部落格園共有。歡迎轉載,但必須保留此段聲明,且在文章頁面明顯位置給出原文連接配接!

繼續閱讀