整合Spring.net到asp.net网站开发中初探

 

Spring提供了一个轻量级的用于构建企业级的应用程序的解决方案。Spring提供一致并清晰的配置并整合AOP(Aspect-Oriented Programming)至你的软件中。Spring.net最耀眼的功能是在中间层提供声明式事务管理用于构建全功能的ASP.NET框架。

Spring.net是一个提供综合的基础结构用于支持企业级.Net开发的应用程序类库。它帮助我们在程序开发过程中减少复杂性。

将Spring.net应用到asp.net中

首先在web.Config中配置:(初次配置建议使用.net framework 2.0,因为其web.config相对简洁一些,可以给配置减少些麻烦)

<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文件:

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 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)); 

}在app_code文件中添加math.cs文件,代码如下:

public class Math 

public int Add(int a, int b) 

return a + b; 

}在web.config稍做些修改如下:

<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> 
</spring> 翻译的文章来源自:http://www.codeproject.com/KB/aspnet/spring-asp.aspx

在执行上述网址下载的源代码时出现如下问题:

一、The IDbCommand and IDbConnection implementation in the assembly MySql.Data could 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.

该问题有些蹊跷,将mysql.data拷贝到本地bin文件夹中可解决

二、Error thrown by a dependency of object 'MySql' defined in 'assembly [Spring.Data]

在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> 参考自: http://forum.springframework.net/archive/index.php/t-950.html

http://forum.springframework.net/showthread.php?t=3564

三、Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition

在web.config中添加如下代码可解决:

<!--TxManager--> 
<object id=”HibernateTransactionManager” type="Spring.Data.NHibernate.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>

整合Spring.net到asp.net网站开发中初探的更多相关文章

  1. ASP.NET网站开发中的配置文件

    来源:微信公众号CodeL 1.配置文件层次分类 Machine.config:  对.netframework整体的配置 web.config(framework目录下):  对所有项目所公有的应用 ...

  2. asp.net 网站开发流程总结

    由于这学期要做asp.net的网站开发,导师让我们在前期做详细的计划说明,时间安排.由于网站开发流程不知道,以及需要学什么指示都是盲懂,所以计划安排需在了解大致流程之后才能做出来,一下是询问同学和在网 ...

  3. 网站开发中很实用的 HTML5 & jQuery 插件

    这篇文章挑选了15款在网站开发中很实用的 HTML5 & jQuery 插件,如果你正在寻找能优化网站,使其更具创造力和视觉冲击,那么本文正是你需要的.这些优秀的 jQuery 插件能为你的网 ...

  4. 网站开发中使用javascript获取浏览器滚动条宽度

    在网站开发中,有时候需要获取浏览器滚动条的宽度,在武汉蚂蹄软件服务中心的技术人员指导之下,我实现了该需求.记录如下: 首先说明一下原理: ①生成一个div,设置滚动条不可见,记录其宽度: ②将上面的d ...

  5. asp.net -mvc框架复习(1)-ASP.NET网站开发概述

    1.网站开发的基本步骤: 2.网站开发的需要的知识结构 (1)网站开发前台页面技术 页面设计:HTML  .CSS+DIV 页面特效:JavaScript.jQery (2)OOP编程核心公共技能 C ...

  6. CGI、ASP、PHP、JSP、 ASP.NET网站开发语言比较

    一.主流网站开发语言的简介及优缺点. 现在主流的网站开发语言主要包括cgi.asp.php.asp.net.jsp等. HTML:当然这是网页最基本的语言,每一个服务器语言都需要它的支持. (一)  ...

  7. 网站开发中的相对URL问题--JSP

    问题描述: 入门网站开发时,我们会在相对URL问题上有疑惑.例如,在一个jsp页面中引入css外部文件, <link rel="stylesheet"          hr ...

  8. Spring Boot学习笔记:项目开发中规范总结

    Spring Boot在企业开发中使用的很广泛,不同的企业有不同的开发规范和标准.但是有些标准都是一致的. 项目包结构 以下是一个项目常见的包结构 以上是一个项目的基本目录结构,不同的项目结构会有差异 ...

  9. 我在网站开发中经常用到的几个js函数01

    这是我在最近的一个网站项目中频繁用到的几个js函数,非常实用.包括:1.js获取地址栏参数:2.返回cookies字符串中指定键对应的值:3.json格式的日期转换为正常格式4.清除cookie. / ...

随机推荐

  1. WPF按钮清空自带样式,以及透明按钮时,Grid的Background属性设置引起"点击"问题.

    1.空样式按钮 <Style x:Key="EmptyButtonStyle" TargetType="Button">            &l ...

  2. SQL Server带游标的SQL

    DECLARE test_cursor CURSOR FOR SELECT ID FROM dbo.T_BD_Restaurant WHERE id <> '0AAB2E55-79F8-4 ...

  3. Android UI SurfaceView的使用-绘制单个图型或多个图形

    新建MyView类继承自SurfaceView: public class MyView extends SurfaceView implements SurfaceHolder.Callback { ...

  4. AndroidUI 布局动画-点九PNG技术

    下面是正常情况与使用点9切图以后的效果对比: <Button android:id="@+id/button1" android:layout_width="fil ...

  5. 全国计算机等级考试二级教程-C语言程序设计_第6章_字符型数据

    #include <stdio.h> main() { char c; char d; c = ; d = '; if (c == d) { printf("yes\n" ...

  6. javascript第四课变量作用域

    局部变量: function f1() { var n1=0;  //局部变量 n1=10; //全局变量,当前页面均可调用 } n1=10;//全局变量 var n1=10;//全局变量 在方法内的 ...

  7. get the first and last collection item in Magento

    $product_collection->getFirstItem() $product_collection->getLastItem()

  8. ubuntu系统下设置静态IP

    改动 /etc/network/interfaces文件 加入下面内容 # The loopback network interface auto lo eth0 iface lo inet loop ...

  9. HBASE学习笔记--shell

    Hbase shell 启动 下载安装hbase client包,填写相关配置后进入,配置相关说明可以参见配置篇 指令:./bin/hbase shell 状态及配置信息查询 查询服务器状态 stat ...

  10. Web-----》》》 一般处理程序 ashx

    一般处理程序 后缀: 前台页面:.ashx 后台页面:.ashx.cs 打开方式:右键程序集--在浏览器中查看--输入url(如http://localhost:6560/firstAshx.ashx ...