【问题标题】:Spring XD Java config doesn't load xml resourceSpring XD Java 配置不加载 xml 资源
【发布时间】:2015-10-21 03:57:25
【问题描述】:

我正在使用 Spring XD 创建流 twittersearch,然后连接到我的推文处理器,然后连接到日志。

我使用 Java 配置类都很好,没有问题,然后我想使用 @ImportResource 在我的 ModuleConfiguration 类中添加 applicationContext.xml

@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);
    }
}

以及applicationContext.xml内容:

<?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>

还有我的流定义:流创建 --name JustCreate --definition "twittersearch --query=Java | tweet-processor | log" --deploy

部署流时出现错误:

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

我也尝试过使用 spring-module.xml 方法(根本不使用 Java 配置)并且该方法有效。

但我只是好奇 Spring XD Java 配置是否不支持 @ImportResource 注释。

谢谢。

【问题讨论】:

    标签: spring-xd


    【解决方案1】:

    一旦找到并解析了配置资源,Spring XD 就会以正常方式从 XML 或 @Configuration 类创建应用程序上下文。 XD 在 config 目录中查找。如果它找到一个 .xml 或 .groovy 文件,它将使用该文件来创建应用程序上下文。如果没有,它将查找 .properties 文件和 base_packages 属性来扫描 @Configuration 类。由于您在 config 目录中有一个 XML 文件,因此 @Configuration 将被忽略。要导入资源,请将它们放在不同的路径中。这可以是 config 的子目录或不同的顶级目录。这在Modules section of the XD reference guide中有详细讨论。

    【讨论】:

    • 由于您的 XML 只添加了 PPC;您可以改用@PropertySource - 以查看this question 的答案为例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-13
    • 2016-07-27
    • 2013-10-24
    相关资源
    最近更新 更多