0

我正在尝试在流应用程序启动时将某个类的实例存储在 mule 注册表中。下面你可以看到我的 java 代码和流程片段。我的问题是有时应用程序部署失败并出现以下错误:

Caused by: java.lang.ClassCastException: com.company.test.sorter.model.Config cannot be cast to org.mule.construct.AbstractFlowConstruct
    at org.mule.module.management.mbean.FlowConstructService.postRegister(FlowConstructService.java:139)
    at org.mule.module.management.agent.ClassloaderSwitchingMBeanWrapper.postRegister(ClassloaderSwitchingMBeanWrapper.java:101)

您可以在下面找到整个堆栈跟踪。我必须重复一遍:这个异常只在某些时候引发,大约每五次部署未更改的应用程序。在大多数情况下,应用程序运行得非常好。我用谷歌搜索了这个异常和类,但没有找到任何解决方案。我正在使用 Mule 3.2.1(独立)。这是一个错误还是我做错了什么?

@XmlRootElement(name = "config")
public class Config  {
    private String x2Regex;
    private String x3Regex;
    private String x2QueueName;
    private String x3QueueName;
    // constructors, getters and setters
}
public class Initializer implements
    MuleContextNotificationListener<MuleContextNotification> {
    @Override
    public void onNotification(MuleContextNotification notification) {
        if (notification.getAction() == MuleContextNotification.CONTEXT_STARTED) {
            try {
                notification.getMuleContext().getRegistry().registerObject("config", new Config());
            } catch (RegistrationException e) {
                // cut
            }
        }
    }
}
<notifications>  
    <notification event="CONTEXT"/>  
    <notification-listener ref="Initializer"/> 
</notifications>
<spring:beans>
    <spring:bean id="Initializer" name="Initializer" class="com.company.test.sorter.Initializer" doc:name="Bean"/>
</spring:beans>

以下是 mule 日志的片段,但有异常:

+ Failed to deploy app 'number-sorter', see below          +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    org.mule.module.launcher.DeploymentException: Failed to deploy application [number-sorter]
    at org.mule.module.launcher.DefaultMuleDeployer.deploy(DefaultMuleDeployer.java:68)
    at org.mule.module.launcher.DeploymentService.start(DeploymentService.java:175)
    at org.mule.module.launcher.MuleContainer.start(MuleContainer.java:157)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.mule.module.reboot.MuleContainerWrapper.start(MuleContainerWrapper.java:56)
    at org.tanukisoftware.wrapper.WrapperManager$12.run(WrapperManager.java:2788)
Caused by: org.mule.api.MuleRuntimeException: MBeans Failed to initialise
    at org.mule.module.management.agent.JmxAgent$MuleContextStartedListener.onNotification(JmxAgent.java:707)
    at org.mule.module.management.agent.JmxAgent$MuleContextStartedListener.onNotification(JmxAgent.java:685)
    at org.mule.context.notification.Sender.dispatch(Sender.java:40)
    at org.mule.context.notification.Policy.dispatch(Policy.java:122)
    at org.mule.context.notification.ServerNotificationManager.notifyListeners(ServerNotificationManager.java:244)
    at org.mule.context.notification.ServerNotificationManager.fireNotification(ServerNotificationManager.java:197)
    at org.mule.DefaultMuleContext.fireNotification(DefaultMuleContext.java:404)
    at org.mule.DefaultMuleContext.start(DefaultMuleContext.java:226)
    at org.mule.module.launcher.application.DefaultMuleApplication.start(DefaultMuleApplication.java:146)
    at org.mule.module.launcher.application.ApplicationWrapper.start(ApplicationWrapper.java:107)
    at org.mule.module.launcher.DefaultMuleDeployer.deploy(DefaultMuleDeployer.java:52)
    ... 8 more
Caused by: javax.management.RuntimeMBeanException: RuntimeException thrown in postRegister method
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.postRegisterInvoke(Unknown Source)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(Unknown Source)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(Unknown Source)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(Unknown Source)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(Unknown Source)
    at org.mule.module.management.agent.JmxAgent.registerFlowConstructServices(JmxAgent.java:428)
    at org.mule.module.management.agent.JmxAgent$MuleContextStartedListener.onNotification(JmxAgent.java:700)
    ... 18 more
Caused by: java.lang.ClassCastException: com.company.test.sorter.model.Config cannot be cast to org.mule.construct.AbstractFlowConstruct
    at org.mule.module.management.mbean.FlowConstructService.postRegister(FlowConstructService.java:139)
    at org.mule.module.management.agent.ClassloaderSwitchingMBeanWrapper.postRegister(ClassloaderSwitchingMBeanWrapper.java:101)
    ... 25 more
4

1 回答 1

1

感觉像一个错误:阅读源代码后,我找不到任何合理的解释来解释为什么 Mule 会尝试在 JMX 中注册您的自定义对象,同时将其误认为是 Flow!

附带说明一下,当您可以使用 Spring 构建对象时,为什么还要使用通知侦听器和 Mule 注册表?

于 2012-05-14T16:33:02.260 回答