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