0
votes

I am using Spring XD to create stream twittersearch then wired to my tweet-processor then wired to log.

I used Java config class all fine no issues, then I wanted to add applicationContext.xml in my ModuleConfiguration class using @ImportResource

@Configuration
@ImportResource("config/applicationContext.xml")
@EnableIntegration
public class ModuleConfiguration {

    @Bean
    MessageChannel input() {
        return new DirectChannel();
    }

    @Bean
    MessageChannel output() {
        return new DirectChannel();
    }

    @Autowired
    TweetProcessor tweetProcessor;

    @Bean
    freemarker.template.Configuration configuration() {
        return new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_23);
    }
}

And the applicationContext.xml content:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>file:/apps/conf/application.properties</value>
            </list>
        </property>
    </bean>

</beans>

And my stream definition: stream create --name JustCreate --definition "twittersearch --query=Java | tweet-processor | log" --deploy

When the stream deployed I got error:

2015-10-21T11:26:26+0800 1.2.1.RELEASE WARN twitterSource-1-1 twitter.TwitterSearchChannelAdapter - Exception while reading stream.
org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'singlenode:default,admin,singlenode,hsqldbServer:9393.JustCreate.0'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers

I have tried also using spring-module.xml approach (not using Java config at all) and that approach works.

But I am just curious whether Spring XD Java config not supporting @ImportResource annotation.

Thanks.

1

1 Answers

0
votes

Spring XD creates an application context in the normal normal way from an XML or @Configuration class once it locates and resolves the configuration resources. XD looks in the config directory. If it finds a .xml or or .groovy file, it will use that file to create the application context. If not, it will look for a .properties file and a base_packages property to scan for @Configuration classes. Since you have an XML file in the config directory, the @Configuration is being ignored. To import resources put them in a different path. This can be a sub-directory of config or a different top level directory. This is discussed in detail in the Modules section of the XD reference guide.