Spring provides a lightweight solution for building enterprise-level applications. Spring provides consistent and clear configuration and integrates AOP (Aspect-Oriented Programming) into your software. Spring.net's most dazzling feature is to provide declarative transaction management on the middle layer for building a full-featured ASP. NET Framework.
Spring.net is an application class library that provides a comprehensive infrastructure to support enterprise-level. Net development. It helps us reduce complexity during program development.
Apply Spring.net to asp.net
First, configure in web. Config: (we recommend that you use. net framework 2.0 for the first configuration, because its web. config is relatively concise and can reduce the configuration trouble)
<Configuration>
<ConfigSections>
<! -- Spring -->
<SectionGroup name = "spring">
<Section name = "context" type = "Spring. Context. Support. WebContextHandler, Spring. Web"/>
<Section name = "objects" type = "Spring. Context. Support. DefaultSectionHandler, Spring. Core"/>
<Section name = "parsers" type = "Spring. Context. Support. NamespaceParsersSectionHandler, Spring. Core"/>
</SectionGroup>
<! -- Spring -->
</ConfigSections>
<Spring>
<Parsers>
</Parsers>
<Context>
<Resource uri = "config: // spring/objects"/>
</Context>
<Objects xmlns = "http://www.springframework.net" xmlns: db = "http://www.springframework.net/database">
<! -- Pages -->
<Object type = "Default. aspx">
</Object>
</Objects>
</Spring>
<Sysyem. web>
<HttpHandlers>
<! -- Spring Handler -->
<Add verb = "*" path = "*. aspx" type = "Spring. Web. Support. PageHandlerFactory, Spring. Web"/>
</HttpHandlers>
<HttpModules>
<Add name = "SpringModule" type = "Spring. Context. Support. WebSupportModule, Spring. Web"/>
</HttpModules>
</Sysyem. web>
</Configuration> Default. aspx. cs file:
Public partial class _ Default: System. Web. UI. Page
{
Private string message;
Public string Message
{
Set {message = value ;}
Get {return message ;}
}
Private Math math;
Public Math
{
Set {math = value ;}
Get {return math ;}
}
Protected void Page_Load (object sender, EventArgs e)
{
Response. Write (Message );
Response. Write ("</br> ");
Response. Write (Math. Add (20, 60 ));
}
} Add the math. cs file to the app_code file. The Code is as follows:
Public class Math
{
Public int Add (int a, int B)
{
Return a + B;
}
} Modify web. config as follows:
<Spring>
......
<Objects xmlns = http://www.springframework.net xmlns: db = "http://www.springframework.net/database">
<Object name = "MyMathObj" type = "Math, App_code"/>
<! -- Pages -->
<Object type = "Default. aspx">
<Property name = "Message" value = "Hello from Spring. Net"/>
<Property name = "Math" ref = "MyMathObj"/>
</Object>
</Objects>
Source of Translation: http://www.codeproject.com/KB/aspnet/spring-asp.aspx
The following problems occur when executing the source code downloaded from the above website:
1. The IDbCommand and IDbConnection implementation in the assembly MySql. data cocould not be found. ensure that the assembly MySql. data is located in the application directory or in the Global Assembly Cache. if the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly.
This problem may be somewhat confusing. It can be solved by copying mysql. data to the local bin folder.
2. Error thrown by a dependency of object 'mysql' defined in 'assembly [Spring. Data]
Add the following code to web. config:
<Runtime>
<AssemblyBinding xmlns = "urn: schemas-microsoft-com: asm. v1">
<DependentAssembly>
<AssemblyIdentity name = "MySql. Data" publicKeyToken = "c5687fc88969c44d" culture = "neutral"/>
<BindingRedirect oldVersion = "0.0.0.0-65535.65535.65535.65535" newVersion = "5.2.5.0"/>
</DependentAssembly>
</AssemblyBinding>
</Runtime> reference from: http://forum.springframework.net/archive/index.php/t-950.html
Http://forum.springframework.net/showthread.php? T = 3564
Iii. Write operations are not allowed in read-only mode (FlushMode. NEVER)-turn your Session into FlushMode. AUTO or remove 'readonly' marker from transaction definition
Add the following code to web. config:
<! -- TxManager -->
<Object id = "HibernateTransactionManager" type = "Spring. Data. nhib.pdf. HibernateTransactionManager, Spring. Data. NHibernate12">
<Property name = "DbProvider" ref = "DbProviderMySQL"/>
<Property name = "SessionFactory" ref = "SessionFactory"/>
</Object>
<Object id = "PersonDaoTx" type = "Spring. Transaction. Interceptor. TransactionProxyFactoryObject, Spring. Data">
<Property name = "PlatformTransactionManager" ref = "HibernateTransactionManager"/>
<Property name = "Target" ref = "PersonDao"/>
<Property name = "TransactionAttributes">
<Name-values>
<Add key = "Save *" value = "PROPAGATION_REQUIRES_NEW"/>
<Add key = "SaveO *" value = "PROPAGATION_REQUIRES_NEW"/>
<Add key = "Delete *" value = "PROPAGATION_REQUIRED"/>
<Add key = "Query *" value = "PROPAGATON_REQUIRED"/>
</Name_values>
</Property>
</Object>