No Argument https://www.e-learn.cn/tag/no-argument zh-hans Mule ESB中entry-point-resolver的使用(6) No Argument Entry Point Resolver https://www.e-learn.cn/topic/3453586 <span>Mule ESB中entry-point-resolver的使用(6) No Argument Entry Point Resolver</span> <span><span lang="" about="/user/107" typeof="schema:Person" property="schema:name" datatype="">守給你的承諾、</span></span> <span>2020-03-01 09:57:31</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"> <p>No Arguments Entry Point Resolver是定位Component类中的无参数方法的.Entry Point Resolver默认会忽略掉继承自Object类的notify(),toString()等方法。配置No Arguments Entry Point Resolver的代码如下</p> <pre><code class="language-xml">&lt;no-arguments-entry-point-resolver acceptVoidMethods="true" /&gt;</code></pre> <p>如果想排除掉某些方法,可以使用exclude-entry-point标签,不过这种情况下默认对Object类的方法的忽略将会失效,需要添加&lt;exclude-object-methods /&gt;节点</p> <pre><code class="language-xml">&lt;no-arguments-entry-point-resolver acceptVoidMethods="true"&gt; &lt;exclude-entry-point method="xxxx" /&gt; &lt;/no-arguments-entry-point-resolver&gt;</code></pre> <p>如果想要在指定方法中进行匹配,可以使用include-entry-point标签</p> <pre><code class="language-xml">&lt;no-arguments-entry-point-resolver acceptVoidMethods="true"&gt; &lt;include-entry-point method="xxxx" /&gt; &lt;/no-arguments-entry-point-resolver&gt;</code></pre> <p>我们在TestComponent中添加两个无参数的方法</p> <pre><code class="language-java">public void NoArgumentEntryPointMethod1() { logger.info("NoArgumentEntryPointMethod is executed"); } public void NoArgumentEntryPointMethod2() { logger.info("NoArgumentEntryPointMethod2 is executed"); }</code></pre> <p>在流程中使用以下配置</p> <pre><code class="language-xml">&lt;no-arguments-entry-point-resolver acceptVoidMethods="true" /&gt;</code></pre> <p>启动项目后,可以看到由于有两个方法匹配,抛出了异常</p> <p>NoArgumentsEntryPointResolver: Found too many possible methods</p> <p>我们加入exclude-entry-point节点忽略掉NoArgumentEntryMethod1方法</p> <pre><code class="language-xml">&lt;no-arguments-entry-point-resolver acceptVoidMethods="true" &gt; &lt;exclude-object-methods /&gt; &lt;exclude-entry-point method="NoArgumentEntryPointMethod1" /&gt; &lt;/no-arguments-entry-point-resolver&gt;</code></pre> <p>这里如果不加exclude-object-methods节点,会抛出异常</p> <p>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()]"</p> <p>从异常信息可以看出,Object类的一系列无参数方法也进入了匹配方法列表,从而会抛异常。</p> <p>设置好后再启动项目,可以看到NoArgumentEntryMethod2方法被匹配执行</p> <p><img height="129" width="703" class="b-lazy" data-src="http://static.oschina.net/uploads/space/2016/0816/144111_AQiX_237688.png" data-original="http://static.oschina.net/uploads/space/2016/0816/144111_AQiX_237688.png" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" /></p> <p>我们再使用include-entry-point节点,匹配NoArgumentEntryMethod1方法</p> <pre><code class="language-xml">&lt;no-arguments-entry-point-resolver acceptVoidMethods="true" &gt; &lt;include-entry-point method="NoArgumentEntryPointMethod1"/&gt; &lt;/no-arguments-entry-point-resolver&gt;</code></pre> <p>启动项目,可以看到NoArgumentEntryMethod1方法被匹配执行</p> <p><img height="162" width="687" class="b-lazy" data-src="http://static.oschina.net/uploads/space/2016/0816/153933_htKB_237688.png" data-original="http://static.oschina.net/uploads/space/2016/0816/153933_htKB_237688.png" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" /></p> <p> </p> <div class="alert alert-success" role="alert"><p>来源:<code>oschina</code></p><p>链接:<code>https://my.oschina.net/u/237688/blog/733481</code></p></div></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/mule-esb" hreflang="zh-hans">Mule ESB</a></div> <div class="field--item"><a href="/tag/entry-point-resolver" hreflang="zh-hans">Entry Point Resolver</a></div> <div class="field--item"><a href="/tag/no-argument" hreflang="zh-hans">No Argument</a></div> </div> </div> Sun, 01 Mar 2020 01:57:31 +0000 守給你的承諾、 3453586 at https://www.e-learn.cn