MVC项目中的Spring.net配置例子
下面是MVC项目中使用Spring.Net融合的例子
1、将Spring.net程序集复制到项目下的packages文件夹中。
2、项目中添加引用Spring.Core.dll、Common.Logging.dll、Spring.Web.Mvc4.dll、Spring.Web.dll
3、修改Web.config,配置节点
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- Spring.Net配置节点 -->
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.MvcContextHandler, Spring.Web.Mvc4"/>
</sectionGroup>
</configSections>
<!-- Spring.Net节点详细配置 -->
<spring>
<context>
<resource uri="file://~/Config/controllers.xml"/>
</context>
</spring>
</configuration>
4、项目中创建Config文件夹,controllers.xml文件。
<?xml version="1.0" encoding="utf-8" ?> <objects xmlns="http://www.springframework.net"> <object type="HX.Shop.UI.Main.Controllers.AdminController, HX.Shop.UI.Main" singleton="false" > <property name="AdminService" ref="AdminService" /> </object> <object name="AdminService" type="HX.Shop.BLL.AdminService, HX.Shop.BLL" singleton="false" > </object> </objects>
5、Global.asax 中修改 SpringMvcApplication
public class MvcApplication : Spring.Web.Mvc.SpringMvcApplication //System.Web.HttpApplication

浙公网安备 33010602011771号