为什么 Spring 集成管理配置在默认情况下不起作用?
Why Spring Integration management configuration doesn't work by default?
我正在研究新的 Spring 集成好处 - 集成管理配置,在 java 文档的基础上,这个是随 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";
所以我有两个误解:
- 为什么在 java 文档中写 -
(defaults to '*')
,但默认值是 ''
,如注释中所示?
- 为什么没有逻辑检查
defaultCountsEnabled
是否为真然后检查 countsEnabled
属性?
P.S. 我不喜欢我需要自己使用自定义注释或在现有注释中设置这些属性来提供默认值。甚至更多:在来源的基础上,同样认为与 属性 defaultStatsEnabled
和 statsEnabled
有关。同样在 java 与 metricsFactory
相关的文档中描述了 The DefaultMetricsFactory is used if omitted
,但似乎我也会遇到错误,很可能是 NoSuchBeanDefinitionException
.
这是一个known bug。
它固定在 master 上(repo.spring.io/snapshots 仓库中的 4.2.1.BUILD-SNAPSHOT);它将在我们计划下周发布的 4.2.1.RELEASE 中修复。
我们未能为默认注释添加测试(无属性);否则我们早就发现了。
我正在研究新的 Spring 集成好处 - 集成管理配置,在 java 文档的基础上,这个是随 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";
所以我有两个误解:
- 为什么在 java 文档中写 -
(defaults to '*')
,但默认值是''
,如注释中所示? - 为什么没有逻辑检查
defaultCountsEnabled
是否为真然后检查countsEnabled
属性?
P.S. 我不喜欢我需要自己使用自定义注释或在现有注释中设置这些属性来提供默认值。甚至更多:在来源的基础上,同样认为与 属性 defaultStatsEnabled
和 statsEnabled
有关。同样在 java 与 metricsFactory
相关的文档中描述了 The DefaultMetricsFactory is used if omitted
,但似乎我也会遇到错误,很可能是 NoSuchBeanDefinitionException
.
这是一个known bug。
它固定在 master 上(repo.spring.io/snapshots 仓库中的 4.2.1.BUILD-SNAPSHOT);它将在我们计划下周发布的 4.2.1.RELEASE 中修复。
我们未能为默认注释添加测试(无属性);否则我们早就发现了。