转--Spring.net web.config配置文件(经过整理和修改)

注:此文只适用于WebForm,Winform中需要将HttpMoudles和HttpHandlers去掉

转载地址:http://blog.163.com/fengzhisha0914@126/blog/static/15031478520113115718158/

需要引入:spring.Aop,spring.core,spring.web,antlr.runtime,common.logging

Web.config配置文件

1. 添加Spring的SectionGroup

 

View Code
1 <sectionGroup name="spring">
2       <section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
3       <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
4 </sectionGroup>

 

2. 添加HttpHandler配置

View Code
1 <add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>

 

3. 添加HttpModule配置(如果不添加的话,会有异常)---注:此行一定要放到HttpModule的第一条,要不然会有报错,我也不知道为什么???那位大侠可告诉一下

View Code
1 <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>

 

4. 最后配置如何依赖注入

View Code
 1 <spring>
 2     <context>
 3       <resource uri="config://spring/objects"/>
 4     </context>
 5     <objects xmlns="http://www.springframework.net">
 6       <object type="Default.aspx">
 7         <property name="Service" ref="myService"/>
 8       </object>
 9       <object id="myService" type="Services.MyService, Services">
10       </object>
11     </objects>
12   </spring>

 

上面那个是定义在Web.config中的Spring节点的写法,下面这个更全一点

<spring>

<!--

配置在Web.config中需要指定type

<context type="Spring.Context.Support.XmlApplicationContext, Spring.Core">

-->

<!--配置在其他xml中不需要指定type-->

    <context>

      <!--<resource uri="config://spring/objects"/>(配置在Web.config中方法)-->

      <resource uri="~/spring.xml.config"/><!--指定其他配置文件-->

    </context>

posted @ 2012-09-16 19:18  倚楼听雨  阅读(613)  评论(0编辑  收藏  举报