给定一个如下所示的 Java 组件
<flow name="MainFlow2" doc:name="MainFlow2">
...
<component class="com.service.gateway.MyService" doc:name="My Gateway"/>
...
</flow>
我在注册自定义代理时尝试获取它
<custom-agent name="my-agent" class="com.monitor.MyAgent"/>
通过做这个
muleContext.getRegistry().lookupObjects(DefaultJavaComponent.class);
看起来这些 java 组件不在注册表中,我没有得到它们。
到目前为止,我有这个解决方法
// Get all flows
for (AbstractFlowConstruct flowConstruct : muleContext.getRegistry().lookupObjects(AbstractFlowConstruct.class)) {
if (flowConstruct instanceof AbstractPipeline) {
//get flow's MessageProcessor
List<MessageProcessor> mgs = ((AbstractPipeline) flowConstruct).getMessageProcessors();
for (MessageProcessor messageProcessor : mgs) {
if (messageProcessor instanceof DefaultJavaComponent) {
DefaultJavaComponent javaComp = (DefaultJavaComponent) messageProcessor;
//GOT IT!
}
}
}
}
您知道如何以编程方式直接获取所有 Java 组件吗?