VS2017 MVC Spring net 環境配置


首先打開管理NuGet程序包。

 

搜索 "spring web",安裝Spring.Web,Spring.Web.Mvc5,Spring.Web.Extensions,

 

搜索Microsoft.AspNet.WebApi,安裝,這個一定要安裝,不然會報錯:找不到依賴項。

安裝完成后,配置Web.Config文件

代碼如下

    <!--Sping.net配置-->
    <sectionGroup name="spring">
      <section name="context" type="Spring.Context.Support.MvcContextHandler, Spring.Web.Mvc5" />
      <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
    </sectionGroup>
  </configSections>
 <spring>
    <context>
      <!--容器配置-->
      <resource uri="config://spring/objects"/>
    </context>
    <objects xmlns="http://www.springframework.net">
      <!--這里放容器里面的所有節點-->
      <description>An  example that demonstrates simple IoC features.</description>
      <!--<object  name="LinkDal" type="Zero.Cmsqc.EFDAL.LinkDal, Zero.Cmsqc.EFDAL" singleton="false" >
      </object>-->

      <object  name="DbSession" type="Zero.Cmsqc.DALFactory.DbSessionFactory, Zero.Cmsqc.DALFactory" singleton="false" factory-method="GetCurrentDbSession" >
      </object>
      <object  name="LinkDal" type="Zero.Cmsqc.EFDAL.LinkDal, Zero.Cmsqc.EFDAL" singleton="false" >
      </object>
      <object  name="LinkService" type="Zero.Cmsqc.BLL.LinkService, Zero.Cmsqc.BLL" singleton="false" >
        <property name="DbSession" ref="DbSession"/>
        <property name="CurrentDal" ref="LinkDal"/>
      </object>
      <object type="Zero.Cmsqc.UI.Controllers.LinkController, Zero.Cmsqc.UI" singleton="false" >
        <property name="LinkService" ref="LinkService"/>
      </object>

    </objects>
  </spring>

 

 再修改 Global.asax 文件,讓MvcApplication繼承SpringMvcApplication,

 

using Spring.Web.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;

namespace Zero.Cms.UI
{
    public class MvcApplication : SpringMvcApplication
    { 
        protected void Application_Start()
        {          
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }
}

 

 到這里配置工作 就完成了!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM