1.web.config Configuration
<?xml version= "1.0" encoding= "Utf-8"?>
<!--
For more information about how to configure an ASP. NET application, go to
http://go.microsoft.com/fwlink/?LinkId=301880
-
<configuration>
<configSections>
<sectiongroup name= "Spring" >
<section name= "Context" type= "Spring.Context.Support.MvcContextHandler, SPRING.WEB.MVC"/>
</sectionGroup>
</configSections>
<connectionStrings>
<add name= "ApplicationServices"
connectionstring= "Data source=.\sqlexpress;integrated Security=sspi; attachdbfilename=| Datadirectory|aspnetdb.mdf; User Instance=true "
Providername= "System.Data.SqlClient"/>
</connectionStrings>
<spring>
<context>
<resource uri= "~/config/controllers.xml"/>
</context>
</spring>
<appSettings>
<add key= "webpages:version" value= "3.0.0.0"/>
<add key= "webpages:enabled" value= "false"/>
<add key= "clientvalidationenabled" value= "true"/>
<add key= "unobtrusivejavascriptenabled" value= "true"/>
</appSettings>
<system.web>
<compilation debug= "true" targetframework= "4.5.2"/>
</system.web>
<runtime>
<assemblybinding xmlns= "Urn:schemas-microsoft-com:asm.v1" >
<dependentAssembly>
<assemblyidentity name= "System.Web.Helpers" publickeytoken= "31bf3856ad364e35"/>
<bindingredirect oldversion= "1.0.0.0-3.0.0.0" newversion= "3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyidentity name= "System.Web.WebPages" publickeytoken= "31bf3856ad364e35"/>
<bindingredirect oldversion= "1.0.0.0-3.0.0.0" newversion= "3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyidentity name= "SYSTEM.WEB.MVC" publickeytoken= "31bf3856ad364e35"/>
<bindingredirect oldversion= "1.0.0.0-5.2.3.0" newversion= "5.2.3.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.codedom>
<compilers>
<compiler language= "C#;cs;csharp" extension= ". Cs"
Type= "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, version=1.0.0.0, Culture=neutral, publickeytoken= 31bf3856ad364e35 "
Warninglevel= "4" compileroptions= "/langversion:6/nowarn:1659;1699;1701"/>
<compiler language= "Vb;vbs;visualbasic;vbscript" extension= ". vb"
Type= "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, version=1.0.0.0, Culture=neutral, publickeytoken= 31bf3856ad364e35 "
Warninglevel= "4" compileroptions= "/langversion:14/nowarn:41008/define:_mytype=\" web\" /optioninfer+ "/>
</compilers>
</system.codedom>
</configuration>
2. Add the Lib folder to the root directory (Spring.core spring.web.mvc Common.Logging.dll Common.Logging.Log4Net.dll)
Assembly reference Add these 4 things
3.mvcapplication registering route rewrite inheritance Springmvcapplication
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;
Using System.Web.Routing;
Using SPRING.WEB.MVC;
Namespace WebApplication12
{
public class Mvcapplication : Springmvcapplication
{
protected override void RegisterRoutes (RouteCollection routes)
{
Routes. Ignoreroute ("{resource}.axd/{*pathinfo}");
Routes. MapRoute (
Name: "Default",
URL: "{controller}/{action}/{id}",
defaults:new {controller = "Home", action = "Index", id = urlparameter.optional}
);
}
protected void Application_Start ()
//{
Arearegistration.registerallareas ();
Routeconfig.registerroutes (routetable.routes);
//}
}
}
3. Add Controllers.xml in the new Config folder under the root directory (right-click Properties always copy my superstition)
<?xml version= "1.0" encoding= "Utf-8"?>
<objects xmlns= "Http://www.springframework.net" >
<object type= "WebApplication12.Controllers.HomeController, WebApplication12" singleton= "false" >
<property name= "Message1" value= "Pirates of the King"/>
</object>
<!--set injection--
<object type= "WebApplication12.Controllers.HomeController, WebApplication12" singleton= "false" >
<property name= "Message" >
<list element-type= "System.String" >
<value>b0 stage</value>
<VALUE>B1 stage</value>
<VALUE>B2 stage</value>
<VALUE>B3 stage</value>
<VALUE>B4 stage</value>
<VALUE>B5 stage</value>
<value>b6 stage</value>
</list>
</property>
</object>
</objects>
4. Controller adds a message property to inject
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;
Namespace Webapplication12.controllers
{
public class Homecontroller:controller
{
Public string Message {get; set;}
Get:home
Public ActionResult Index ()
{
viewdata["message"] = message;
return View ();
}
}
}
4. View Call
@{
Layout = null;
}
<! DOCTYPE html>
<meta name= "viewport" content= "Width=device-width"/>
<title>Index</title>
<body>
<div>
</div>
</body>
SPRING.WEB.MVC Injection (Controller attribute injection)