为什么Spring Integration管理配置默认不起作用?

时间:2015-09-29 23:11:51

标签: java spring spring-integration

我正在调查新的Spring Integration优势 - 集成管理配置,在java docs的基础上提供了4.2版本。

我已经编写了简单的基于java的上下文。

/**
 * @author Eugene Stepanenkov
 */
@Configuration
@EnableIntegration
@EnableIntegrationManagement
@IntegrationComponentScan(basePackages = {
        "com.stepsoft.study.flow",
        "com.stepsoft.study.configuration.flow",
        "com.stepsoft.study.flow.messaging"
})
@ComponentScan(basePackages = {
        "com.stepsoft.study.flow",
        "com.stepsoft.study.configuration.flow",
        "com.stepsoft.study.flow.messaging"
})
@Import({
        DataContext.class,
        ImportFlowContext.class
})
@PropertySource("classpath:flow.properties")
public class FlowContext {

    @Value("${flow.defaultPoller.fixedDelay}")
    private int fixedDelay;

    @Value("${flow.defaultPoller.maxMessagesPerPoll}")
    private int maxMessagesPerPoll;

    @Bean(name = DEFAULT_POLLER)
    public PollerMetadata defaultPoller() {

        PollerMetadata pollerMetadata = new PollerMetadata();
        pollerMetadata.setTrigger(new PeriodicTrigger(fixedDelay, MILLISECONDS));
        pollerMetadata.setMaxMessagesPerPoll(maxMessagesPerPoll);

        return pollerMetadata;
    }
}

当执行上下文初始化时,我得到IllegalArgumentException enabledCountsPatterns must not be empty

我在源头找到了这个地方

    /**
     * Set the array of simple patterns for component names for which message counts will
     * be enabled (defaults to '*').
     * Enables message counting (`sendCount`, `errorCount`, `receiveCount`)
     * for those components that support counters (channels, message handlers, etc).
     * This is the initial setting only, individual components can have counts
     * enabled/disabled at runtime. May be overridden by an entry in
     * {@link #setEnabledStatsPatterns(String[]) enabledStatsPatterns} which is additional
     * functionality over simple counts. If a pattern starts with `!`, counts are disabled
     * for matches. For components that match multiple patterns, the first pattern wins.
     * Disabling counts at runtime also disables stats.
     * @param enabledCountsPatterns the patterns.
     */
    public void setEnabledCountsPatterns(String[] enabledCountsPatterns) {
        Assert.notEmpty(enabledCountsPatterns, "enabledCountsPatterns must not be empty");
        this.enabledCountsPatterns = Arrays.copyOf(enabledCountsPatterns, enabledCountsPatterns.length);
    }

据我所知,此属性来自注释EnableIntegrationManagement

    /**
     * A list of simple patterns for component names for which message counts will be
     * enabled (defaults to '*'). Enables message
     * counting (`sendCount`, `errorCount`, `receiveCount`) for those components that
     * support counters (channels, message handlers, etc). This is the initial setting
     * only, individual components can have counts enabled/disabled at runtime. May be
     * overridden by an entry in {@link #statsEnabled() statsEnabled} which is additional
     * functionality over simple counts. If a pattern starts with `!`, counts are disabled
     * for matches. For components that match multiple patterns, the first pattern wins.
     * Disabling counts at runtime also disables stats.
     * Defaults to no components, unless JMX is enabled in which case, defaults to all
     * components. Overrides {@link #defaultCountsEnabled()} for matching bean names.
     * @return the patterns.
     */
    String[] countsEnabled() default "";

但与此同时:

   /**
    * The default setting for enabling counts when a bean name is not matched by
    * {@link #countsEnabled() countsEnabled}.
    * @return the value; false by default, or true when JMX is enabled.
    */
   String defaultCountsEnabled() default "false";

所以我有两个误解:

  1. 为什么在java文档中编写了(defaults to '*'),但默认值为'',如注释中所示?
  2. 为什么没有逻辑可以检查defaultCountsEnabled是否为真,然后检查countsEnabled属性?
  3. P.S。我不希望自己需要使用自定义注释或在现有注释中设置这些属性来提供默认值。更重要的是:在来源的基础上,同样的想法与defaultStatsEnabled夫妇的财产statsEnabled有关。同样在与metricsFactory相关的java文档中描述The DefaultMetricsFactory is used if omitted,但似乎我也会收到错误,很可能是NoSuchBeanDefinitionException

1 个答案:

答案 0 :(得分:1)

这是known bug

它固定在master(repo.spring.io/snapshots repo中的4.2.1.BUILD-SNAPSHOT)上;它将在我们计划下周发布的4.2.1.RELEASE中修复。

我们未能为默认注释添加测试(没有属性);否则我们会早点发现它。