首页 新闻 会员 周边 捐助

SPRING 注入 MVC 中。Global.asax.cs配置出错

0
悬赏园豆:10 [已关闭问题] 关闭于 2009-12-17 07:49

 

代码
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

 

这是我捕获到的错误。

导致的错误

InputStream is null from Resource = [assembly [Repository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null], resource [Repository.Repository.xml]]

说明: 执行当前 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 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。


堆栈跟踪:

[ObjectDefinitionStoreException: InputStream is null from Resource = [assembly [Repository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null], resource [Repository.Repository.xml]]]   Spring.Objects.Factory.Xml.XmlObjectDefinitionReader.LoadObjectDefinitions(IResource resource) +392   Spring.Objects.Factory.Support.AbstractObjectDefinitionReader.LoadObjectDefinitions(String location) +380   Spring.Objects.Factory.Support.AbstractObjectDefinitionReader.LoadObjectDefinitions(String[] locations) +158   Spring.Context.Support.AbstractXmlApplicationContext.LoadObjectDefinitions(XmlObjectDefinitionReader objectDefinitionReader) +135   Spring.Context.Support.AbstractXmlApplicationContext.LoadObjectDefinitions(DefaultListableObjectFactory objectFactory) +121   Spring.Context.Support.AbstractXmlApplicationContext.RefreshObjectFactory() +162   Spring.Context.Support.AbstractApplicationContext.Refresh() +303   Spring.Context.Support.WebApplicationContext..ctor(String name, Boolean caseSensitive, IApplicationContext parentContext, String[] configurationLocations) +114   Spring.Context.Support.WebApplicationContext..ctor(String name, Boolean caseSensitive, String[] configurationLocations) +59   _dynamic_Spring.Context.Support.WebApplicationContext..ctor(Object[] ) +242   Spring.Reflection.Dynamic.SafeConstructor.Invoke(Object[] arguments) +72   Spring.Context.Support.RootContextInstantiator.InvokeContextConstructor(ConstructorInfo ctor) +272   Spring.Context.Support.ContextInstantiator.InstantiateContext() +217   Spring.Context.Support.ContextHandler.InstantiateContext(IApplicationContext parentContext, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources) +225   Spring.Context.Support.WebContextHandler.InstantiateContext(IApplicationContext parent, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources) +444   Spring.Context.Support.ContextHandler.Create(Object parent, Object configContext, XmlNode section) +646[ConfigurationErrorsException: Error creating context 'spring.root': InputStream is null from Resource = [assembly [Repository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null], resource [Repository.Repository.xml]]]   System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) +202   System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) +1061   System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) +1431   System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission) +56   System.Configuration.BaseConfigurationRecord.GetSection(String configKey) +8   System.Web.HttpContext.GetSection(String sectionName) +47   System.Web.Configuration.HttpConfigurationSystem.GetSection(String sectionName) +39   System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String configKey) +6   System.Configuration.ConfigurationManager.GetSection(String sectionName) +78   Spring.Util.ConfigurationUtils.GetSection(String sectionName) +131   Spring.Context.Support.WebApplicationContext.GetContextInternal(String virtualPath) +1505   Spring.Context.Support.WebApplicationContext.GetRootContext() +181   Spring.Context.Support.WebSupportModule.Init(HttpApplication app) +697   System.Web.HttpApplication.InitModulesCommon() +65   System.Web.HttpApplication.InitModules() +43   System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers) +729   System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context) +298   System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +107   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +289
撞破南墙的主页 撞破南墙 | 初学一级 | 园豆:160
提问于:2009-12-14 16:04
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册