您需要在配置中手动声明注释解析器才能处理注释。
考虑这个 POJO:
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 配置一起使用:
<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