Messaging Rhino ServiceBus启动时获取异常

Messaging Rhino ServiceBus启动时获取异常,messaging,spring.net,servicebus,rhino-servicebus,Messaging,Spring.net,Servicebus,Rhino Servicebus,我的系统分为两部分。两个部分相互通信 其他使用Rhino服务总线。 Windows 7上没有问题,但是如果我在其他地方启动它 (WinXP,Server2003,…)我得到以下异常 当我调用Rhino.ServiceBus.Hosting.DefaultHost.Start(..): System.NullReferenceException:对象引用未设置为对象的实例。 位于Spring.Objects.Factory.Support.AbstractObjectFactory.GetObje

我的系统分为两部分。两个部分相互通信 其他使用Rhino服务总线。 Windows 7上没有问题,但是如果我在其他地方启动它 (WinXP,Server2003,…)我得到以下异常 当我调用
Rhino.ServiceBus.Hosting.DefaultHost.Start(..)

System.NullReferenceException:对象引用未设置为对象的实例。
位于Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectFromFactoryObject(IFactoryObject工厂,字符串objectName,RootObjectDefinition)
位于Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectForInstance(对象实例、字符串名称、字符串规范名称、RootObjectDefinition)
位于Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectInternal(字符串名称、类型requiredType、对象[]参数、布尔值)
位于Spring.Objects.Factory.Support.AbstractObjectFactory.GetObject(字符串名称)
位于Spring.Context.Support.AbstractApplicationContext.GetObject(字符串名称)
位于Rhino.ServiceBus.Spring.ApplicationContextensions.Get(IAApplicationContext上下文,类型)
在Rhino.ServiceBus.Spring.applicationContextensions.Get[T](IConfigurationApplicationContext上下文)
在Rhino.ServiceBus.Spring.SpringBootStrapper.GetInstance[T]()
位于Rhino.ServiceBus.Hosting.DefaultHost.InitailizeBus(字符串名称)
位于Rhino.ServiceBus.Hosting.DefaultHost.Start(字符串名称)
以下是Spring日志的片段形式:

2012-01-14 13:25:01084调试Spring.Objects.Factory.Support.DefaultListableObjectFactory-在对象“351a5f07-e33d-4be0-84cf-1738a8feba24”初始化后调用IOObjectPostProcessors
2012-01-14 13:25:01084调试Spring.Objects.Factory.Support.DefaultListableObjectFactory-GetObjectInternal:返回objectname 351a5f07-e33d-4be0-84cf-1738a8feba24的实例
2012-01-14 13:25:01084错误Spring.Objects.Factory.Support.DefaultListableObjectFactory-GetObjectInternal:获取对象Rhino.ServiceBus.Msmq.FlatQueueStrategy时出错
2012-01-14 13:25:01084错误Spring.Objects.Factory.Support.DefaultListableObjectFactory-GetObjectInternal:获取对象Rhino.ServiceBus.Msmq.MsmqTransport时出错
2012-01-14 13:25:01084错误Spring.Objects.Factory.Support.DefaultListableObjectFactory-GetObjectInternal:获取对象1a769f24-5410-4cee-8d7a-76c3a91b1ce1时出错
问题已解决: 在MSMQ版本3或更低版本(在Windows XP、Windows Server 2003等系统上)中,不支持子队列,因此Rhino SB使用FlatQueueStrategy来管理队列。 配置Spring对象容器时会出现问题。具体来说,Rhino.ServiceBus.Spring.SpringBuilder类中有两个地方需要进行修改

1) 方法注册SMQTTransport

if (queueStrategyType.GetConstructor(new[] { typeof(IQueueStrategy), typeof(Uri) }) != null)
{
    applicationContext.RegisterSingleton(queueStrategyType, typeof (IQueueStrategy).FullName, applicationContext.Get<IEndpointRouter>(), config.Endpoint);
}
else
{
    // use default
    applicationContext.RegisterSingleton(queueStrategyType);
}
if(queueStrategyType.GetConstructor(new[]{typeof(iqueueestrategy),typeof(Uri)})!=null)
{
applicationContext.RegisterSingleton(queueStrategyType,typeof(iqueueUserTregy).FullName,applicationContext.Get(),config.Endpoint);
}
其他的
{
//使用默认值
applicationContext.RegisterSingleton(queueStrategyType);
}
if语句的第二部分始终被调用,因为FlatQueueStrategy没有具有IQueueStrategy和Uri类型参数的构造函数。 但是它甚至没有没有没有参数的构造函数。因此,FlatQueueStrategy未在对象容器中正确注册。 本部分的修改将是:

if (queueStrategyType.GetConstructor(new[] { typeof(IEndpointRouter), typeof(Uri) }) != null)
{
    applicationContext.RegisterSingleton(queueStrategyType, typeof (IQueueStrategy).FullName, applicationContext.Get<IEndpointRouter>(), config.Endpoint);
}
else
{
    // use default
    applicationContext.RegisterSingleton(queueStrategyType);
}
    applicationContext.RegisterSingleton<IServiceLocator>(() => new SpringServiceLocator(applicationContext));
    applicationContext.RegisterSingletons<IBusConfigurationAware>(typeof(IServiceBus).Assembly);
    applicationContext.RegisterSingleton<IReflection>(() => new DefaultReflection());
    applicationContext.RegisterSingleton<IEndpointRouter>(() => new EndpointRouter());

    foreach (var busConfigurationAware in applicationContext.GetAll<IBusConfigurationAware>())
    {
        busConfigurationAware.Configure(config, this);
    }

    foreach (var module in config.MessageModules)
    {
        applicationContext.RegisterSingleton(module, module.FullName);
    }

    applicationContext.RegisterSingleton(config.SerializerType);
if(queueStrategyType.GetConstructor(新[]{typeof(IEndpointRouter),typeof(Uri)})!=null)
{
applicationContext.RegisterSingleton(queueStrategyType,typeof(iqueueUserTregy).FullName,applicationContext.Get(),config.Endpoint);
}
其他的
{
//使用默认值
applicationContext.RegisterSingleton(queueStrategyType);
}
2) 方法RegisterDefaultServices

下一个问题是RegisterDefaultServices方法:

    applicationContext.RegisterSingleton<IServiceLocator>(() => new SpringServiceLocator(applicationContext));
    applicationContext.RegisterSingletons<IBusConfigurationAware>(typeof(IServiceBus).Assembly);

    foreach (var busConfigurationAware in applicationContext.GetAll<IBusConfigurationAware>())
    {
        busConfigurationAware.Configure(config, this);  // here is the method RegisterMsmqTransport called
    }

    foreach (var module in config.MessageModules)
    {
        applicationContext.RegisterSingleton(module, module.FullName);
    }

    applicationContext.RegisterSingleton<IReflection>(() => new DefaultReflection());
    applicationContext.RegisterSingleton(config.SerializerType);
    applicationContext.RegisterSingleton<IEndpointRouter>(() => new EndpointRouter());
applicationContext.RegisterSingleton(()=>new SpringServiceLocator(applicationContext));
applicationContext.RegisterSingleton(类型为(IServiceBus.Assembly));
foreach(applicationContext.GetAll()中的var-busConfigurationAware)
{
configurationaware.Configure(config,this);//下面是调用的RegisterMsmqTransport方法
}
foreach(config.MessageModules中的var模块)
{
applicationContext.RegisterSingleton(模块,模块,全名);
}
applicationContext.RegisterSingleton(()=>new DefaultReflection());
applicationContext.RegisterSingleton(config.SerializerType);
applicationContext.RegisterSingleton(()=>new EndpointRouter());
在对象容器中注册IEndpointRouter之前调用RegisterMsmQTTransport方法。 IEndpointRouter用于方法RegisterMsmQTTransport(请参见1),因此方法调用

    applicationContext.Get<IEndpointRouter>()
applicationContext.Get()
生成一个异常。 这里的修改是:

if (queueStrategyType.GetConstructor(new[] { typeof(IEndpointRouter), typeof(Uri) }) != null)
{
    applicationContext.RegisterSingleton(queueStrategyType, typeof (IQueueStrategy).FullName, applicationContext.Get<IEndpointRouter>(), config.Endpoint);
}
else
{
    // use default
    applicationContext.RegisterSingleton(queueStrategyType);
}
    applicationContext.RegisterSingleton<IServiceLocator>(() => new SpringServiceLocator(applicationContext));
    applicationContext.RegisterSingletons<IBusConfigurationAware>(typeof(IServiceBus).Assembly);
    applicationContext.RegisterSingleton<IReflection>(() => new DefaultReflection());
    applicationContext.RegisterSingleton<IEndpointRouter>(() => new EndpointRouter());

    foreach (var busConfigurationAware in applicationContext.GetAll<IBusConfigurationAware>())
    {
        busConfigurationAware.Configure(config, this);
    }

    foreach (var module in config.MessageModules)
    {
        applicationContext.RegisterSingleton(module, module.FullName);
    }

    applicationContext.RegisterSingleton(config.SerializerType);
applicationContext.RegisterSingleton(()=>new SpringServiceLocator(applicationContext));
applicationContext.RegisterSingleton(类型为(IServiceBus.Assembly));
applicationContext.RegisterSingleton(()=>new DefaultReflection());
applicationContext.RegisterSingleton(()=>new EndpointRouter());
foreach(applicationContext.GetAll()中的var-busConfigurationAware)
{
busConfigurationAware.Configure(config,this);
}
foreach(config.MessageModules中的var模块)
{
applicationContext.RegisterSingleton(模块,模块,全名);
}
applicationContext.RegisterSingleton(config.SerializerType);

太好了,你把答案贴在这里了!也请接受它,这样每个人都知道你的问题已经解决了。