把容器从<section name="context" type="Spring.Context.Support.ContextHandler,Spring.Core" />改为 <section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web" />
1 <?xml version="1.0" encoding="utf-8"?> 2 3 <!-- 4 有关如何配置 ASP.NET 应用程序的详细信息,请访问 5 http://go.microsoft.com/fwlink/?LinkId=169433 6 --> 7 8 <configuration> 9 10 <configSections> 11 <!--节点组--> 12 <sectionGroup name="spring"> 13 <!--容器--> 14 <!--<section name="context" type="Spring.Context.Support.ContextHandler,Spring.Core" />--> 15 16 <!-- 17 更改context容器要注意: 18 第一:版本号必须要写当前使用的DLL兼容 19 第二:如果添加使用Spring.Web还需要配置 20 <system.webServer> 21 <modules runAllManagedModulesForAllRequests="true"> 22 <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web" /> 23 </modules> 24 </system.webServer> 25 否则报:Can't get WebApplicationContext object from ContextRegistry.GetContext(): Resource handler for the 'web' protocol is not defined 错误 26 27 --> 28 <section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web" /> 29 <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" /> 30 </sectionGroup> 31 <section name="databaseSettings" type="System.Configuration.NameValueSectionHandler" /> 32 </configSections> 33 <spring> 34 <context> 35 <resource uri="~/App_Data/Config/Spring/Common.xml" /> 36 <resource uri="~/App_Data/Config/Spring/Hibernate.xml" /> 37 <resource uri="~/App_Data/Config/Spring/Dao.xml" /> 38 </context> 39 </spring> 40 41 <databaseSettings> 42 <add key="db.server" value="." /> 43 <add key="db.database" value="Spring" /> 44 <add key="db.user" value="sa" /> 45 <add key="db.password" value="123" /> 46 </databaseSettings> 47 48 49 <system.web> 50 <compilation debug="true" targetFramework="4.5" /> 51 <httpRuntime targetFramework="4.5" /> 52 </system.web> 53 54 55 <system.webServer> 56 <directoryBrowse enabled="true" /> 57 <!--Can't get WebApplicationContext object from ContextRegistry.GetContext(): Resource handler for the 'web' protocol is not defined--> 58 <modules runAllManagedModulesForAllRequests="true"> 59 <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web" /> 60 </modules> 61 </system.webServer> 62 63 </configuration>
报错:Can't get WebApplicationContext object from ContextRegistry.GetContext(): Resource handler for the 'web' protocol is not defined
解决方案:添加<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web" />节点
1 <system.webServer> 2 <directoryBrowse enabled="true" /> 3 <!--Can't get WebApplicationContext object from ContextRegistry.GetContext(): Resource handler for the 'web' protocol is not defined--> 4 <modules runAllManagedModulesForAllRequests="true"> 5 <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web" /> 6 </modules> 7 </system.webServer>
第二个问题:如果需要改变容品的对象 如:<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web" />
第一步:引用对应的:Spring.Web程序集,这个程序集必须与相关的DLL相关,否则会报错:如

浙公网安备 33010602011771号