Mule ESB中entry-point-resolver的使用(6) No Argument Entry Point Resolver

守給你的承諾、 提交于 2020-03-01 09:57:31

No Arguments Entry Point Resolver是定位Component类中的无参数方法的.Entry Point Resolver默认会忽略掉继承自Object类的notify(),toString()等方法。配置No Arguments Entry Point Resolver的代码如下

<no-arguments-entry-point-resolver  acceptVoidMethods="true" />

如果想排除掉某些方法,可以使用exclude-entry-point标签,不过这种情况下默认对Object类的方法的忽略将会失效,需要添加<exclude-object-methods />节点

<no-arguments-entry-point-resolver  acceptVoidMethods="true">
 <exclude-entry-point method="xxxx" />
</no-arguments-entry-point-resolver>

如果想要在指定方法中进行匹配,可以使用include-entry-point标签

<no-arguments-entry-point-resolver  acceptVoidMethods="true">
 <include-entry-point method="xxxx" />
</no-arguments-entry-point-resolver>

我们在TestComponent中添加两个无参数的方法

public void NoArgumentEntryPointMethod1()
{
	logger.info("NoArgumentEntryPointMethod is executed");
}
	
public void NoArgumentEntryPointMethod2()
{
	logger.info("NoArgumentEntryPointMethod2 is executed");
}

在流程中使用以下配置

<no-arguments-entry-point-resolver  acceptVoidMethods="true" />

启动项目后,可以看到由于有两个方法匹配,抛出了异常

NoArgumentsEntryPointResolver: Found too many possible methods

我们加入exclude-entry-point节点忽略掉NoArgumentEntryMethod1方法

<no-arguments-entry-point-resolver  acceptVoidMethods="true" >
  <exclude-object-methods />
  <exclude-entry-point method="NoArgumentEntryPointMethod1" />
</no-arguments-entry-point-resolver>

这里如果不加exclude-object-methods节点,会抛出异常

Found too many possible methods on object "entrypointresolvertest.TestComponent" that accept parameters "{}", Methods matched are "[public void entrypointresolvertest.TestComponent.NoArgumentEntryPointMethod2(), public final void java.lang.Object.wait() throws java.lang.InterruptedException, public java.lang.String java.lang.Object.toString(), public native int java.lang.Object.hashCode(), public final native java.lang.Class java.lang.Object.getClass(), public final native void java.lang.Object.notify(), public final native void java.lang.Object.notifyAll()]"

从异常信息可以看出,Object类的一系列无参数方法也进入了匹配方法列表,从而会抛异常。

设置好后再启动项目,可以看到NoArgumentEntryMethod2方法被匹配执行

我们再使用include-entry-point节点,匹配NoArgumentEntryMethod1方法

<no-arguments-entry-point-resolver  acceptVoidMethods="true" >
     <include-entry-point method="NoArgumentEntryPointMethod1"/>
</no-arguments-entry-point-resolver>

启动项目,可以看到NoArgumentEntryMethod1方法被匹配执行

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!