无法从 ContextRegistry.GetContext() 获取 WebApplicationContext 对象:“web”的资源处理程序;协议未定义
我陷入了在 Web 表单项目下配置 web.config 文件的困境,以便获取 WebApplicationContext 的实例(位于 Global.asax),然后能够使用scope="application | session | request",
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
<spring>
<context type="Spring.Context.Support.WebApplicationContext, Spring.Web">
<resource uri="~/Configuration/Spring.xml" />
</context>
</spring>
<httpHandlers>
<add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
</httpHandlers>
<httpModules>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</httpModules>
然后我尝试将 WebApplicationContext 添加到我的 Application 对象,以便在任何 .aspx 页面上使用;
protected void Application_Start(object sender, EventArgs e)
{
//Exception happens on next line!
Application.Add("ContainerID", ContextRegistry.GetContext());
}
我得到的例外是;
"Error creating context 'spring.root': Resource handler for the 'web' protocol is not defined. Spring.NET"
我花了一些时间谷歌搜索,但没有成功。我在 Spring.NET 文档中找到了; “在 Web 应用程序中 Spring 提供了 通过添加自定义 HTTP 模块和 HTTP 来配置的 WebApplicationContext 实现 处理程序到您的 Web.config 文件。请参阅有关 Web 配置的部分以获取更多详细信息。”但这根本没有发生。
请问有人可以帮助我吗?
I'm stucked in configuring my web.config file under a web forms project in order to get an instance of WebApplicationContext (at Global.asax) and then being able to use scope="application | session | request"
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
<spring>
<context type="Spring.Context.Support.WebApplicationContext, Spring.Web">
<resource uri="~/Configuration/Spring.xml" />
</context>
</spring>
<httpHandlers>
<add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
</httpHandlers>
<httpModules>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</httpModules>
I'm then trying to add the WebApplicationContext to my Application object, in order to cosume on any .aspx page;
protected void Application_Start(object sender, EventArgs e)
{
//Exception happens on next line!
Application.Add("ContainerID", ContextRegistry.GetContext());
}
Exception I'm getting is;
"Error creating context 'spring.root': Resource handler for the 'web' protocol is not defined. Spring.NET"
I have have spent some time googling, but no success. Ive found at Spring.NET documentation;
"In web applications Spring provides
a WebApplicationContext implementation which is configured by adding a custom HTTP module and HTTP
handler to your Web.config file. See the section on Web Configuration for more details." But it is in no way happening.
Please, could someone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
spring.net 容器未在
Application_Start
上初始化。顺便说一句,为什么要在
Application
存储桶中添加容器?对我来说这听起来像是一个反模式......the spring.net container is not initialized on
Application_Start
.and btw, why would you want to add the container in the
Application
bucker? It sounds like an antipattern to me...将其添加到system.webServer配置节点:
如果您在IIS7中使用integratedMode
Add this to system.webServer config node:
If you use integratedMode in IIS7