Spring. Net learning Notes 1.

Source: Internet
Author: User
Spring. net Article There are also many examples, but there are very few examples or notes for beginners.

1: Add the following configurations to the Web. config file of the website:
(Note: configsections must be the first element in configuration. It is estimated that this is the XML principle, just like Delphi. Program As defined in variables, variables must be defined first in the process. Here, we define the node .) Code
<! --  
SP1: You must register this class in the <configsections> node of the. NET configuration file,
After the node processor is registered, the <spring> node in the configuration file can be started.
Function. (Configsections must be the first element in configuration.
Otherwise, an error occurs during compilation .)
Context: List of container resources (no small number of resources, errors may occur if fewer resources are used)
Objects: list of objects in the container (no fewer objects, errors will occur if fewer objects are used)
-->
< Configsections >
< Sectiongroup Name = "Spring" >
< Section Name = "Context" Type = "Spring. Context. Support. webcontexthandler, spring. Web" />
< Section Name = "Objects" Type = "Spring. Context. Support. defaultsectionhandler, spring. Core" />
</ Sectiongroup >
</ Configsections >

2: implement the nodes defined by spring. ( Code There are comments in it. I will not talk about it here.
<Resource uri = "assembly: // piggy. net. web/piggy. net. web/webtest. XML "/> This means piggy. net. piggy under the Web assembly. net. webtest. xml configuration file. Note that this configuration file must set its "generate operation" to "embedded resources ". You can run the test to change the relevant Assembly, namespace, and file name.
) Code
<! --
SP2: configure the spring container so that the configuration does not need to be explicitly created in the program.
Spring container, thus reducing the coupling of the program to spring.
<Context> the type attribute of a node is optional. In Windows applications, the default value is spring. Context. Support. xmlapplicationcontext.
-->
< Spring >
< Context >
<! -- SP3: the configuration file here refers to the XML file that includes the spring. Net object definition, not the. config file. -->
< Resource Uri = "Config: // spring/objects" />
<! -- The URI syntax for referencing embedded resources in. Net assembly is as follows:
Assembly: // <assemblyname>/<namespace>/<resourcename>
Assembly: // <Assembly>/<namespace>/<Resource Name>
Sp_manual: add different xml configuration information for different projects. For example:
Example: <resource uri = "assembly: // dz_portal.app/spring.net _ bean_sysdepartmentpageadmin.xml"/>
-->
< Resource Uri = "Assembly: // piggy. net. Web/piggy. net. Web/webtest. xml" />
</ Context >
<! -- SP4: The xmlns element of the objects node is required. Different namespaces must be added based on different applications. -->
< Objects Xmlns = "Http://www.springframework.net" />
</ Spring >

3: Add spring support and spring object factory processor to <system. Web>: Code
<! -- SP5: The following seems to be necessary. I don't know why. If not
The following httpmodules and httphandlers do not associate spring
Like injection into the program -->
< Httpmodules >
< Add Name = "Spring" Type = "Spring. Context. Support. websuppmodule module, spring. Web" />
</ Httpmodules >

< Httphandlers >
< Add Verb = "*" Path = "*. Aspx" Type = "Spring. Web. Support. pagehandlerfactory, spring. Web" />
</ Httphandlers >

4: Add the following content to the webtest. xml configuration file in the piggy. net. Web namespace under piggy. net. Web assembly: Code
<! -- Must start with <objects xmlns = 'HTTP: // www.springframework.net '>
It is the start, and the reason is unknown.
-->
< Objects Xmlns = 'HTTP: // www.springframework.net' >
<! -- Page Definition -->
< Object Type = "~ /Default. aspx"   >
< Property Name = "Test" Value = "Corecommbll"   />
</ Object >
</ Objects >

5: defines the page implementation property injection (the default page default. aspx created here is used ): Code
Protected   Void Page_load ( Object Sender, eventargs E)
{
Label1.text=Mtest;
}
Private   String Mtest =   " 1111 " ;
Public   String Test
{
Get   {ReturnMtest ;}
Set   {Mtest=Value ;}
}

Run the program and you will see what you want.

Original Works from the effort to be lazy, reprint please explain the source of the article: http://www.cnblogs.com/kfarvid/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.