首页 新闻 会员 周边 捐助

请教大神解决一下spring.net问题,解决有红包。非常感谢

0
悬赏园豆:100 [已解决问题] 解决于 2017-02-06 12:51

我用的是mvc4.0和framework4.5的开发环境,spring.net用的是2.0.0.40000-M1的版本,现在报如异常

786744873

 

 

“/”应用程序中的服务器错误。


 

No context registered. Use the 'RegisterContext' method or the 'spring/context' section from your configuration file.

说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: Spring.Context.ApplicationContextException: No context registered. Use the 'RegisterContext' method or the 'spring/context' section from your configuration file.

源错误: 

执行当前 Web 请求期间生成了未经处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。


堆栈跟踪: 

[ApplicationContextException: No context registered. Use the 'RegisterContext' method or the 'spring/context' section from your configuration file.]
   Spring.Context.Support.ContextRegistry.GetContext() in f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Core\Context\Support\ContextRegistry.cs:255
   Spring.Web.Mvc.SpringMvcApplication.BuildDependencyResolver() in f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Web.Mvc4\SpringMvcApplication.cs:75
   Spring.Web.Mvc.SpringMvcApplication.Application_BeginRequest(Object sender, EventArgs e) in f:\bamboo-home\xml-data\build-dir\SPRNET-RELEASE-JOB1\src\Spring\Spring.Web.Mvc4\SpringMvcApplication.cs:59
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +141
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

 


版本信息: Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.6.1073.0

 

 

一个大西瓜咚咚咚的主页 一个大西瓜咚咚咚 | 初学一级 | 园豆:112
提问于:2017-02-05 20:53
< >
分享
最佳答案
0

 

你没加配置吧。

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
  <!--业务层仓储,非单例模式-->
  <object id="BLLSessionFactory" type="BLLMsSQL.BLLSessionFactory,BLLMsSQL" singleton="false" />
  <object id="BLLSession" type="BLLMsSQL.BLLSession,BLLMsSQL" singleton="false" />
  <!--数据层仓储-->
  <object id="DBSessionFactory" type="DALMsSQL.DBSessionFactory,DALMsSQL" />
</objects>


web.config文件加:

<spring>
<context>
<resource uri="~/Config/objects.xml" />
</context>
</spring>

 

Spring依赖注入帮助类:

/// <summary>
    /// Spring依赖注入
    /// </summary>
    public class SpringHelper
    {
        /// <summary>
        /// 日志
        /// </summary>
        private static LogHelper _logHelper = new LogHelper(MethodBase.GetCurrentMethod().DeclaringType);

        /// <summary>
        /// Spring.Net上下文
        /// </summary>
        private static IApplicationContext SpringContext
        {
            get
            {
                try
                {
                    return ContextRegistry.GetContext();
                }
                catch (Exception exception)
                {
                    _logHelper.Error(exception.ToString());
                    return null;
                }
            }
        }

        /// <summary>
        /// 使用Spring操作配置文件并转化为对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="objName"></param>
        /// <returns></returns>
        public static T GetObject<T>(string objName) where T : class
        {
            try
            {
                return (T)SpringContext.GetObject(objName);
            }
            catch (Exception exception)
            {
                _logHelper.Error(exception.ToString());
                return null;
            }
        }
    }

 

收获园豆:80
大师兄丶 | 小虾三级 |园豆:843 | 2017-02-06 09:59
其他回答(1)
0

No context registered. Use the 'RegisterContext' method or the 'spring/context' section from your configuration file.

配置好了吗

收获园豆:20
吴瑞祥 | 园豆:29449 (高人七级) | 2017-02-06 08:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册