简体   繁体   中英

Mule ESB 3 transformer cannot be converted to MessageProcessor

I'm trying to follow the transformer example in the documentation that converts a string input into a list of URLs, but it's throwing an error.

The example is here: http://www.mulesoft.org/documentation/display/MULE3USER/Transformer+Annotation#TransformerAnnotation-WorkingwithCollections

My code for the transformer is copy-pasted from theirs.

When I first did it, I set the transformer by putting in my config xml:

<custom-transformer class="com.test.transformer.StringToListTransformer" doc:name="StringToUrlList"/>

Noting the requirement to 'register' the transformer, I later added in the beginning of the file (after the opening tag):

<spring:bean id="stringToListTransformer" class="com.test.transformer.StringToListTransformer"/>

However, when I run the app, I get the following error:

Exception in thread "main" org.mule.module.launcher.DeploymentInitException: IllegalStateException: Cannot convert value of type [com.test.transformer.StringToListTransformer] to required type [org.mule.api.processor.MessageProcessor] for property 'messageProcessors[3]': no matching editors or conversion strategy found

You can't use a class annotated with @Transformer as a custom-transformer because it is not a real org.mule.api.processor.MessageProcessor . Only real message processors can be used directly in the XML configuration and invoked explicitly.

As the doc for @Transformer says:

There is no mechanism in Mule 3.x to actually invoke a transformer which is being constructed from an annotated method.

If you want to have your transformer kick-in in a flow, you'll need to use:

<auto-transformer returnClass="java.util.List.class"/>

assuming it returns a list and there are no other suitable registered transformers with a higher priority.

Otherwise, create a real transformer by extending org.mule.transformer.AbstractMessageTransformer and then use it with custom-transformer .

请使用Java Component而不是Java Transformer ..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM