[英]Why Spring Integration management configuration doesn't work by default?
我正在研究新的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";
所以我有兩個誤解:
(defaults to '*')
,但默認值為''
如注釋中所示)? defaultCountsEnabled
是否為true,然后檢查countsEnabled
屬性? PS我不喜歡自己使用自定義注釋或在現有屬性中設置這些屬性來提供默認值。 更:在源的基礎上同認為這是涉及到財產defaultStatsEnabled
在一對夫妻帶着statsEnabled
。 同樣在與metricsFactory
相關的java文檔中, The DefaultMetricsFactory is used if omitted
但看來我也會收到錯誤,很可能是NoSuchBeanDefinitionException
。
這是一個已知的錯誤 。
它固定在master(在repo.spring.io/snapshots repo中的4.2.1.BUILD-SNAPSHOT)上; 它將在我們計划下周發布的4.2.1.RELEASE中修復。
我們沒有為默認注釋添加測試(沒有屬性); 否則我們會更早發現它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.