asp.net mvc5中spring.net的配置和使用
来源:互联网 发布:软件可靠性方法 pdf 编辑:程序博客网 时间:2024/04/30 08:18
添加必要的引用
MVC5应用中必要的dll如下:
Common.Logging.dll
Spring.Core.dll
Spring.Web.dll
Spring.Web.Mvc5.dll
Spring.Web.Extensions.dll
安装如下Nuget包:
install-package spring.coreinstall-package spring.webinstall-package spring.web.mvc5install-package spring.web.extensions
配置spring.net
在MVC项目下添加Config文件夹,新增俩个xml:controllers.xml
,services.xml
如何配置?参考:http://blog.csdn.net/zhaobw831/article/details/78039380
controllers.xml:
<?xml version="1.0" encoding="utf-8" ?><objects xmlns="http://www.springframework.net"> <description>An example that demonstrates simple IoC features.</description> <!--object的name可以自定义,property中的属性name不能自定义--> <object name="" type="SpringNet.MVC.Controllers.HomeController,SpringNet.MVC" singleton="false"> <property name="test" ref="TestService"></property> </object></objects>
services.xml:
<?xml version="1.0" encoding="utf-8" ?><objects> <object name="TestService" type="SpringNet.Service.TestClass,SpringNet.Service"> </object></objects>
右键属性,将这俩个xml的输出目录改为总是输出,如下:
修改web.config
在configuration下的第一个节点添加:
<!--spring.net 配置开始--> <configSections> <sectionGroup name="spring"> <section name="context" type="Spring.Context.Support.MvcContextHandler, Spring.Web.Mvc5" /> </sectionGroup> </configSections> <spring> <context> <resource uri="file://~/Config/controllers.xml" /> <resource uri="file://~/Config/services.xml" /> </context> </spring> <!--spring.net 配置结束-->
修改Global.asax.cs的父类,添加测试代码
将System.Web.HttpApplication
改为:Spring.Web.Mvc.SpringMvcApplication
HomeController.cs:
Service.TestClass test { get; set; }public ActionResult Test(){ string result = test.TestGet(); return Content(result);}
业务层下的TestClass.cs:
public class TestClass { public string TestGet() { return "this is test content"; } }
运行程序,发现一个错误:
原因为未引用System.Web.Http
,可添加dll引用,也可以再nuget包中添加webapi引用:
install-package microsoft.aspnet.webapi
重新运行程序,成功:
源码
本文源码:Github
spring.net源码:https://github.com/spring-projects/spring-net
阅读全文
0 0
- asp.net mvc5中spring.net的配置和使用
- asp.net MVC5 sitemap 的使用
- 整合ASP.NET MVC5,Spring.Net,NHibernate
- asp.net mvc5中使用缓存依赖SqlCacheDependency
- asp.net mvc5中使用缓存依赖SqlCacheDependency
- NLog 在Asp.NET MVC5中使用文件和数据库设置
- ASP.NET MVC5----了解我们使用的@HTML帮助类
- 在ASP.NET MVC5中实现具有服务器端过滤、排序和分页的GridView
- ASP.Net中配置和使用FCKeditor
- ASP.Net中配置和使用FCKeditor
- ASP.NET MVC5使用Area区域
- asp.net mvc5 安装
- ASP.net MVC5 简介
- ASP.NET MVC5+MySql使用ASP.NET 身份验证
- ASP.NET MVC5修改namespace的问题
- .NET MVC5中使用SignalR2 Demo
- MVC5中使用ReactJS.NET入门
- vs2013下, asp.net mvc5 使用和发布rdlc报表的步骤 ,使用ef来获取数据
- PAT1002 写出这个数 (20) JAVA
- 10 Linux Commands Every Developer Should Know
- memcache服务器软件安装步骤
- 转折点
- 斯坦福分词有无词库对比
- asp.net mvc5中spring.net的配置和使用
- fb_var_screeninfo 解析
- [LeetCode]Symmetric Tree
- 获得Z-WAVE产品的完整可配置参数列表
- 五子棋之极大极小
- 模板方法模式
- 最有用的idea快捷键整理(自定义)
- Hibernate 映射文件使用方式案例
- d3画图表