首先,在ASP.NET MVC5项目右键,如下图所示,选择“管理Nuget程序包。。。”

然后,在弹出的页面的搜索框中输入“spring.web”,在返回结果中选择Spring.Web和Spring.Web.MVC5以及Spring.Core,等待安装

至此,基本的Spring.Net环境所需要的外部程序已经安装完成.

然后,接下来我们配置mvc项目的web.config文件,配置完成的截图如下:

代码如下:

<configuration>
<configSections> <!-- Entity Framework configuration -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> <!--log4net的块配置-->
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
<!--Spring.Net块配置-->
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.MvcContextHandler, Spring.Web.Mvc5" />
</sectionGroup>
</configSections>
<!--Spring.Net的容器的配置节点-->
<spring>
<context>
<resource uri="file://~/Config/common.xml" />
<resource uri="file://~/Config/service.xml" />
<resource uri="file://~/Config/controllers.xml" />
</context>
</spring>

接下来,为大家介绍Spring.Net的功能的使用(依赖注入,构建类的时候赋予属性)。比如我在Controler中想使用BLL层的一个类中的方法。那么可以如下面所示

控制器:UserInfoController

BLL层类:IUserInfoService

首先,在控制器中定义一个属性。

其次,在配置文件中,添加控制器层对应的controller.xml文件,文件路径在web.config中已经声明

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"> <object type="UI.Controllers.UserInfoController, UI" singleton="false" >
<property name="u" ref ="UserInfoService" />
</object> <object type="UI.Controllers.LoginController, UI" singleton="false" >
<property name="UserInfoService" ref ="UserInfoService" />
</object> </objects>
  <object type="UI.Controllers.UserInfoController, UI" singleton="false" >
<property name="u" ref ="UserInfoService" />
</object>

这段的意思是在这个控制器下的“u”这个字段的赋值是由UserInfoService配置,对应的service.xml文件如下配置:

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"> <object name="UserInfoService" type="BLL.UserInfoService, BLL" singleton="false" >
</object> </objects>

这样就可以做到赋值了。然后比较重要的一步是在程序开始前进行赋值,具体的操作是在Global.asax文件中:

public class MvcApplication : SpringMvcApplication

让MvcApplication来继承SpringMvcApplication这个类,

通过查看源码我们知道这个类也是继承与我们asp.net中最重要的类HttpApplication。

VS这个软件真的越来越强大了,省去了我们许多去寻找各种dll的时间。以上各个过程都是实际项目中一个小测试用的,经测试可以调用BLL层中的方法

,如果大家有什么不理解或者出现问题的地方,欢迎讨论。或者加我qq:1224327326,备注spring.net

VS2015ASP.NET MVC5项目中Spring.NET配置方法(超详细)的更多相关文章

  1. Spring Boot 日志配置方法(超详细)

    默认日志 Logback : 默认情况下,Spring Boot会用Logback来记录日志,并用INFO级别输出到控制台.在运行应用程序和其他例子时,你应该已经看到很多INFO级别的日志了. 从上图 ...

  2. 初识quartz 并分析 项目中spring整合quartz的配置【原创+转载】

    初识quartz 并分析 项目中spring整合quartz的配置[原创+转载]2018年01月29日 12:08:07 守望dfdfdf 阅读数:114 标签: quartz 更多个人分类: 工具 ...

  3. Maven项目中Spring整合Mybatis

    Maven项目中Spring整合Mybatis 添加jar包依赖 spring需要的jar包依赖 <dependency> <groupId>org.springframewo ...

  4. [ionic开源项目教程] - 第5讲 如何在项目中使用全局配置

    第5讲 如何在项目中使用全局配置? Q:ionic开发,说纯粹一点,用的就是html+css+js,那么无疑跟web开发的方式是类似的.在这里给大家分享一个小技巧,如何在项目中使用全局配置? A:我的 ...

  5. JAVA项目中引用Logback的方法

    一.简介 本文主要讲JAVA项目中引入Logback的方法. 二.解决 1.引入依赖. <!--Begin LogBack Log--> <!-- https://mvnreposi ...

  6. ThinkPHP公共配置文件与各自项目中配置文件组合的方法

    ThinkPHP公共配置文件与各自项目中配置文件组合的方法 文章TAG:thinkphp 公共配置文件 时间:2014-11-25来源:www.aspku.com 作者:源码库 文章热度: 146 ℃ ...

  7. VB的一些项目中常用的通用方法-一般用于验证类

    1.VB的一些项目中常用的通用方法: ' 设置校验键盘输入值,数字 Public Function kyd(key As Integer) As Integer Dim mychar mychar = ...

  8. IBM MQ + WebSphere + Spring JMS配置方法

    IBM MQ + WebSphere + Spring JMS配置方法  首先要在WAS里面配置IBM MQ作为JMS消息的提供者,在WAS管理控制台: Resources->JMS Provi ...

  9. centos7 yum搭建lnmp环境及配置wordpress超详细教程

    yum安装lnmp环境是最方便,最快捷的一种方法.源码编译安装需要花费大量的人类时间,当然源码编译可以个性化配置一些其它功能.目前来说,yum安装基本满足我们搭建web服务器的需求. 本文是我根据近期 ...

随机推荐

  1. ExportGrid Aspose.Cells.dll

    using Aspose.Cells; using Aspose.Words; using System; using System.Collections; using System.Collect ...

  2. win32 注册表操作

    创建键 RegCreateKeyEx int SetRecordVideoSavedDays(int newSavedDays) { HKEY hSubKey = NULL; LONG lRet = ...

  3. SharePoint 开发小结

    目标:将sharepoint网站对接Office 365 最直接的API:How to: Add Office 365 APIs to a Visual Studio project http://m ...

  4. [C#]this.Invoke和this.BeginInvoke的区别

    private void button1_Click(object sender, EventArgs e) { "; this.Invoke(new EventHandler(delega ...

  5. ubuntu的应用中心打不开、闪退

    原因没有细究,但问题已经解决简单粗暴: 1.更新列表 apt-get update apt-get dist-upgrade 2.重新安装应用中心 apt-get install  --reinsta ...

  6. 一波水题 MZOJ 1035: 贝克汉姆

    #include <bits/stdc++.h> using namespace std; ; int n,m; int v[N],w[N],f[N]; int main() { scan ...

  7. linux 磁盘挂载及查看磁盘

    blkid命令实例 .列出当前系统中所有已挂载文件系统的类型: sudo blkid .显示指定设备 UUID: sudo blkid -s UUID /dev/sda5 .显示所有设备 UUID: ...

  8. oracle 分组中排序(rank函数)

    需求: 查询每个供应商在每个类型产品销售的top50中有多少 分析: 1.查询,以指定字段(供应商.产品类型)分组,取每个分组的前50行,查看每个供应商的数量 2.使用rank函数给每个供应商.每个类 ...

  9. floor函数

    C++中 可以用floor函数来截断小数部分 floor(x)返回一个不大于x的整数,有点像取整函数

  10. Fiddler建好代理后,能连到手机,但手机不能上网了是什么原因

    依次 tools(工具) >>   fiddler options(fiddler选项)   >>   connections( 连接) >>allow remot ...