2013-03-27 89 views
0

我想在騾子中使用@Function註釋。我發現它只有 this page@ Mule中的功能註釋

但我不能得到好的結果。

我做了一個新的項目,增加了Java組件,創建一個新的類並複製該代碼

public class MyComponent { 
    public Object process(@XPath("/Envelope") Document doc 
             @Function("uuid") String id) { 
     // do stuff 
    } 
} 

,但我有很多的誤區。我想我必須配置其他的東西,但我不知道什麼,也不知道如何使用@Function

+0

你展示的代碼不使用

package com.acme; import org.mule.api.annotations.expression.XPath; import org.mule.api.annotations.expressions.Function; import org.w3c.dom.Document; public class AnnotatedPojo { public Object process(@XPath("/Envelope") final Document doc, @Function("uuid") final String id) { return "Envelope text: " + doc.getDocumentElement().getTextContent() + " - ID: " + id; } } 

你可以用這個Mule配置使用'@ Function' ... – 2013-03-28 21:53:20

+0

@DavidDossot對不起,我修改了我的代碼 – maryam 2013-04-06 07:11:19

+0

@DavidDossot可以幫我或者擴展更多?你可以解釋其他步驟 – maryam 2013-04-06 08:09:18

回答

1

您需要在您的配置中手動聲明註釋解析器才能處理註釋。

考慮這個POJO:

<spring:bean class="org.mule.config.endpoint.RegistryBackedAnnotationsParserFactory" /> 

<flow name="testAnnotatedPojo"> 
    <http:inbound-endpoint address="http://localhost:8080/pojo" 
     exchange-pattern="request-response" /> 

    <component class="com.acme.AnnotatedPojo" /> 
</flow> 

調用示例:

$ curl -H "Content-Type: application/xml" http://localhost:8080/pojo -d'<Envelope>foo</Envelope>' 
Envelope text: foo - ID: 9133fc7d-a07f-11e2-b560-4d5f883736c4 
+0

非常感謝你的幫助非常好goooood – maryam 2013-04-09 04:07:40