IIS7集成模式初始化Spring.NET容器(Request is not available in this context exception in Application_Start问题)
来源:互联网 发布:java创建对象 编辑:程序博客网 时间:2024/05/20 18:53
一般Spring容器是在执行第一个请求的时候触发的,但我碰到个需求,必须在应用程序启动的时候就要能够初始化Spring上下文。换句话说,我在Application_Start时就要能够执行
ContextRegistry.GetContext()
我使用了SignalR框架,为了和Spring一起协同工作,我需要使SignalR内置的IoC容器与Spring.NET容器协同工作(SignalR容器同时能够获取Spring容器中的对象,这不是本文重点)。
说一下本文出处(http://mvolo.com/iis7-integrated-mode-request-is-not-available-in-this-context-exception-in-applicationstart/)
解决的思路是将初始化工作延迟到第一次请求再执行(包括MVC注册路由等)
在global.asax中添加如下私有类
private class FirstRequestInitialization { private static bool s_InitializedAlready = false; private static Object s_lock = new Object(); // Initialize only on the first request public static void Initialize(HttpContext context) { if (s_InitializedAlready) { return; } lock (s_lock) { if (s_InitializedAlready) { return; }//这里的内容就是原本要放在Application_Start中做的事情 DependencyResolver.SetResolver(new SpringMvcDependencyResolver(ContextRegistry.GetContext())); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); s_InitializedAlready = true; } } }
随后在覆盖BeginRequest方法
protected void Application_BeginRequest(object sender, EventArgs e){ FirstRequestInitialization.Initialize(Context);}
- IIS7集成模式初始化Spring.NET容器(Request is not available in this context exception in Application_Start问题)
- vim: the command is not available in this version
- google maps navigation is not yet available in this location
- the command is not available in this version: syntax on
- GWT + Spring : javax.naming.NameNotFoundException: Name userDao is not bound in this Context
- Name [spring.liveBeansView.mbeanDomain] is not bound in this Context错误
- Name [spring.liveBeansView.mbeanDomain] is not bound in this Context. Unable to find
- Name java:comp is not bound in this Context解决办法
- Name java:comp is not bound in this Context
- Name jdbc is not bound in this Context
- 该死的java:comp is not bound in this Context
- Name jdbc is not bound in this context
- name jndi is not bound in this context
- as3跟flex中图像加载问题 Error: addChild() is not available in this class. Instead, use addElement() or modi
- 错误Service Microsoft.Practices.CompositeWeb.Interfaces.ISiteMapBuilderService is not available in the current context解决办法
- tomcat5.0 下JNDI javax.naming.NameNotFoundException: Name jdbc is not bound in this Context 问题的解决
- 'release' is unavailable: not available in automat
- Sorry, the command is not available in this version: syntax enable的解决方法
- udf udaf udtf
- Oracle 远程连接访问出错ORA-01031:Insufficient privileges!
- 递归回溯 暴力枚举 (总结)
- android开发文档之resource-drawable用法
- ADO 访问SQL数据库
- IIS7集成模式初始化Spring.NET容器(Request is not available in this context exception in Application_Start问题)
- OpenStack安装部署管理中常见问题解决方法(OpenStack-Lite-FAQ)
- #pragma once相关
- ffmpeg文档2:输出到屏幕
- Java/编程规范
- 解决listview的item为自定义viewgroup时,viewgroup子view press时,整个viewgroup都被按下的问题
- 我姐和我女友是如何学编程的
- ffmpeg文档3:播放声音
- init、loadView、viewDidLoad、viewDidUnload、dealloc的关系