[英]Spring.Net. ContextRegistry.GetContext() exception, cannot configure Common.Logging
I cannot get the IApplication context for my console app 我无法获得控制台应用程序的IApplication上下文
I get an exception with this detail: The type initializer for 'Spring.Context.Support.ContextRegistry' threw an exception.
我得到了一个如此详细的异常: The type initializer for 'Spring.Context.Support.ContextRegistry' threw an exception.
With inner exception: Could not configure Common.Logging from configuration section 'common/logging
有内部异常: Could not configure Common.Logging from configuration section 'common/logging
There's clearly something basic I've not hooked up, but I'm not sure what. 很明显,我还没有了解一些基本的知识,但是我不确定是什么。
using Spring.Context;
using Spring.Context.Support;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
IApplicationContext ctx = ContextRegistry.GetContext();
}
}
}
And my app.config looks like this: 我的app.config看起来像这样:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="config://spring/objects"/>
</context>
<objects xmlns="http://www.springframework.net">
<description>An example that demonstrates simple IoC features. </description>
</objects>
</spring>
</configuration>
The type initializer for 'Spring.Context.Support.ContextRegistry' threw an exception “ Spring.Context.Support.ContextRegistry”的类型初始值设定项引发了异常
This is valueable information and Spring.net is really good at providing additional information. 这是有价值的信息,Spring.net确实擅长提供其他信息。 Whenever Spring.net throws something, be sure to read the InnerException
. 每当Spring.net抛出异常时,请务必阅读InnerException
。
WHen I edit my config I get the messages: Could not find schema information for the attribute #. 当我编辑配置时,得到以下消息:找不到属性#的架构信息。 for # = 'uri', 'context', 'resource' and 'spring' 对于#='uri','context','resource'和'spring'
This is normal if you didn't install the schemas. 如果您没有安装模式,这是正常的。 You can download the schemas at their site and find additional information in their docs . 您可以在其站点上下载这些架构 ,并在其文档中找到其他信息 。 Please note that this is optional and spring runs without those schemas. 请注意,这是可选的,spring运行时没有这些模式。
Spring.Net uses Common Logging as facility for logging, you have to add the logging configuration to your app.config
and the proper library to the referenced assemblies. Spring.Net使用通用日志记录作为记录工具,您必须将记录配置添加到app.config
,并将适当的库添加到引用的程序集中。
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
<arg key="level" value="DEBUG" />
<arg key="showLogName" value="true" />
<arg key="showDataTime" value="true" />
<arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
</factoryAdapter>
</logging>
</common>
</configuration>
http://netcommon.sourceforge.net/docs/1.2.0/reference/html/logging.html#logging-declarative-config http://netcommon.sourceforge.net/docs/1.2.0/reference/html/logging.html#logging-declarative-config
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.