public class SpringControllerFactory : IControllerFactory
{
/// <summary>
/// Default ControllerFactory
/// </summary>
private static DefaultControllerFactory defalutf = null;
public IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName)
{
//get spring context
// RegisterContext.获取上下文的引用
//获取上下文的引用
WebApplicationContext ctx = ContextRegistry.GetContext() as WebApplicationContext;
string controller = controllerName + "Controller";
//查找是否配置该Controller
if (ctx.ContainsObject(controller))
{
object controllerf = ctx.GetObject(controller);
return (IController)controllerf;
}
else
{
if (defalutf == null)
{
defalutf = new DefaultControllerFactory();
}
return defalutf.CreateController(requestContext, controllerName);
}
}
public void ReleaseController(IController controller)
{
//get spring context
IApplicationContext ctx = ContextRegistry.GetContext();
if (!ctx.ContainsObject(controller.GetType().Name))
{
if (defalutf == null)
{
defalutf = new DefaultControllerFactory();
}
defalutf.ReleaseController(controller);
}
}
}
Global.asax.cs中
protected void Application_Start()
{
ControllerBuilder.Current.SetControllerFactory(typeof(Controllers.SpringControllerFactory));
RegisterRoutes(RouteTable.Routes);
}
[System.ArgumentException] {"The controller factory type
'Controllers.SpringControllerFactory' must implement the IControllerFactory interface.\r\n参数名:
controllerFactoryType"} System.ArgumentException
这是我捕获到的错误。
导致的错误
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: Spring.Objects.Factory.ObjectDefinitionStoreException: InputStream is null from Resource = [assembly [Repository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null], resource [Repository.Repository.xml]]
源错误:
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。 |
堆栈跟踪:
|