国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

整合Spring.net到asp.net網站開發中初探

2019-11-14 16:38:56
字體:
來源:轉載
供稿:網友

整合SPRing.net到asp.net網站開發中初探

http://www.veryhuo.com 2009-10-21 烈火網 投遞稿件 我有話說
 

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] 

Error2

在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>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 静乐县| 喀喇| 哈密市| 贺兰县| 东港市| 高州市| 白银市| 朝阳市| 蒙阴县| 宝鸡市| 大竹县| 英吉沙县| 达拉特旗| 昌黎县| 嵩明县| 越西县| 仙游县| 出国| 连平县| 通州市| 通渭县| 杭州市| 隆昌县| 盱眙县| 黄平县| 乡宁县| 团风县| 察雅县| 任丘市| 法库县| 淮南市| 南安市| 南靖县| 宁河县| 综艺| 通州区| 苍梧县| 肥东县| 大荔县| 金湖县| 临沂市|