Reputation: 2674
I have created a Spring XD module, in the likeness of the example tweet transformer. The Spring docs say that you can either use a spring-module.properties
and spring-module.xml
configuration under src/main/resources/config/
or a dedicated ModuleConfiguration.java
file, which defines a Bean. However, if I only use the latter it won't run. XD complains that it cannot determine the module type.
If I add the spring-modules.properties
and the module xml, it works. My ModuleConfiguration.java
looks like this:
package mypackage;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.messaging.MessageChannel;
@Configuration
@EnableIntegration
public class ModuleConfiguration {
@Bean
MessageChannel input() {
return new DirectChannel();
}
@Bean
MessageChannel output() {
return new DirectChannel();
}
@Bean
MyTransformer transformer() {
return new MyTransformer();
}
}
My pom.xml inherits from the spring module pom:
<parent>
<groupId>org.springframework.xd</groupId>
<artifactId>spring-xd-module-parent</artifactId>
<version>1.3.0.RELEASE</version>
<relativePath/>
</parent>
The Transformer looks like this:
package mypackage;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.Transformer;
@MessageEndpoint
public class MyTransformer
{
@Transformer( inputChannel = "input", outputChannel = "output" )
public String transform( String payload )
{
return "Test";
}
}
Upvotes: 1
Views: 390
Reputation: 21883
In your src/main/resources/config/spring-modules.properties
add the following.
base_packages=mypackage
This will enable the ModuleConfiguration to be picked up by the Spring XD Engine and which will in turn load your custom Transformer MyTransformer
.
Everything else looks good.
Upvotes: 2