まず、以下の私の例外情報を見てください:
exception time:2013-10-15 09:08:30,765 [1]
exception level:ERROR
exception class:logerror [(null)]
SpringFactory.GetObject(adminFacade)
System.InvalidOperationException: root context is currently in creation. You must not call ContextRegistry.GetContext() from e.g. constructors of your singleton objects
at Spring.Context.Support.ContextRegistry.InitializeContextIfNeeded()
at Spring.Context.Support.ContextRegistry.GetContext()
at Domain.common.SpringFactory.GetObject(String objectId) in F:\gitlab\huatongmis.git\HuaTongBusinessWeb\Domain\common\SpringFactory.cs:line 38
私のプロジェクト ログ ファイルには、そのような例外情報がいくつかありますが、実際にはプロジェクトが崩壊することはありません。しかし、私はそれをひどい問題として扱います. それは長い間私を困惑させました.
コード ファイルの例外ポイントを参照してください。
public class SpringFactory
{
private static IApplicationContext _applicationContext;
private SpringFactory(){}
public static Object GetObject(string objectId)
{
try
{
if (_applicationContext == null)
{
_applicationContext = ContextRegistry.GetContext();
}
}
catch (Exception ex)
{
LogHelper.WriteLog(string.Format("SpringFactory.GetObject({0})",objectId), ex);
}
return _applicationContext.GetObject(objectId);
}
}
私はこのようにIOcを使用します
public class Order : System.Web.Services.WebService
{
public HTSoapHeader htSoapHeader;
private OrderFacade orderFacade { get; set; }
private TicketFacade ticketFacade { get; set; }
private CarrentalFacade carrentalFacade { get; set; }
private AdminFacade adminFacade { get; set; }
public Order()
{
orderFacade = (OrderFacade)SpringFactory.GetObject("orderFacade");
ticketFacade = (TicketFacade)SpringFactory.GetObject("ticketFacade");
carrentalFacade = (CarrentalFacade)SpringFactory.GetObject("carrentalFacade");
adminFacade = (AdminFacade)SpringFactory.GetObject("adminFacade");
}
}
それがどのように発生し、問題を解決する方法。あなたの答えを楽しみにしています、ありがとう
今日、global.asax で spring.net インジェクションを使用していることを覚えています。コードは次のとおりです。
public class Global : System.Web.HttpApplication
{
private AdminFacade adminFacade;
public Global()
{
//
//initial log
var path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase +
WebConfigurationManager.AppSettings["log4net"];
var fi = new System.IO.FileInfo(path);
log4net.Config.XmlConfigurator.Configure(fi);
adminFacade = (AdminFacade)SpringFactory.GetObject("adminFacade");
}
void Application_Start(object sender, EventArgs e)
{
//print profile sql
HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();
//load all rights
AllSystemRights.Rights = adminFacade.GetRightSer().LoadAllAllSystemRights();
}
.........other events
}
これがspring.core.dllの例外ポイントであり、ソースコードです
public static IApplicationContext GetContext()
{
lock (syncRoot)
{
InitializeContextIfNeeded();
if (rootContextName == null)
{
throw new ApplicationContextException("No context registered. Use the 'RegisterContext' method or the 'spring/context' section from your configuration file.");
}
return GetContext(rootContextName);
}
}
メソッド 'InitializeContextIfNeeded' のコード:
private static void InitializeContextIfNeeded()
{
if (rootContextName == null)
{
if (rootContextCurrentlyInCreation)
{
throw new InvalidOperationException("root context is currently in creation. You must not call ContextRegistry.GetContext() from e.g. constructors of your singleton objects");
}
rootContextCurrentlyInCreation = true;
try
{
ConfigurationUtils.GetSection("spring/context");
}
finally
{
rootContextCurrentlyInCreation = false;
}
}
}
あなたが助けるものは何でも望まれます