Skip to content

Commit 2a225a3

Browse files
committed
Make Tests and Docs more precise and scoped.
Signed-off-by: Jiandong Ma <jiandong.ma.cn@gmail.com>
1 parent 9c02447 commit 2a225a3

5 files changed

Lines changed: 24 additions & 77 deletions

File tree

spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationRegistrar.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ public class IntegrationRegistrar implements ImportBeanDefinitionRegistrar, Envi
5252
}
5353
}
5454

55-
static final String ENV_ENABLE_MESSAGING_ANNOTATIONS_PROCESSING = "spring.integration.annotations.enable";
56-
5755
@SuppressWarnings("NullAway.Init")
5856
private Environment environment;
5957

@@ -78,10 +76,10 @@ public void registerBeanDefinitions(@Nullable AnnotationMetadata importingClassM
7876
registerDefaultConfiguringBeanFactoryPostProcessor(registry);
7977
registerIntegrationConfigurationBeanFactoryPostProcessor(registry);
8078

81-
if (importingClassMetadata != null) {
82-
if (this.environment.getProperty(ENV_ENABLE_MESSAGING_ANNOTATIONS_PROCESSING, Boolean.class, true)) {
83-
registerMessagingAnnotationPostProcessors(registry);
84-
}
79+
if (importingClassMetadata != null
80+
&& this.environment.getProperty("spring.integration.annotations.enable", Boolean.class, true)) {
81+
82+
registerMessagingAnnotationPostProcessors(registry);
8583
}
8684
registerGatewayProxyInstantiationPostProcessor(registry);
8785
}

spring-integration-core/src/main/java/org/springframework/integration/config/xml/AnnotationConfigParser.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ public class AnnotationConfigParser implements BeanDefinitionParser {
5757

5858
ExtendedAnnotationMetadata importingClassMetadata = new ExtendedAnnotationMetadata(element);
5959
BeanDefinitionRegistry registry = parserContext.getRegistry();
60-
integrationRegistrar
61-
.registerBeanDefinitions(importingClassMetadata, registry);
60+
integrationRegistrar.registerBeanDefinitions(importingClassMetadata, registry);
6261
if (DomUtils.getChildElementByTagName(element, "enable-publisher") != null) {
6362
new PublisherRegistrar()
6463
.registerBeanDefinitions(importingClassMetadata, registry);

spring-integration-core/src/test/java/org/springframework/integration/config/IntegrationRegistrarTests.java

Lines changed: 17 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,15 @@
2020

2121
import org.assertj.core.api.Assertions;
2222
import org.junit.jupiter.api.Test;
23-
import org.junitpioneer.jupiter.RetryingTest;
2423

2524
import org.springframework.context.ApplicationContext;
2625
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
2726
import org.springframework.context.annotation.Bean;
2827
import org.springframework.context.annotation.Configuration;
29-
import org.springframework.context.annotation.Import;
3028
import org.springframework.integration.annotation.ServiceActivator;
31-
import org.springframework.integration.channel.DirectChannel;
3229
import org.springframework.integration.context.IntegrationContextUtils;
30+
import org.springframework.messaging.MessageHandler;
3331
import org.springframework.test.context.support.TestPropertySourceUtils;
34-
import org.springframework.util.StopWatch;
3532

3633
/**
3734
* @author Jiandong Ma
@@ -42,109 +39,63 @@ class IntegrationRegistrarTests {
4239
void testDefaultEnableMessagingAnnotationsProcessing() {
4340
try (var context = new AnnotationConfigApplicationContext(Config.class)) {
4441

45-
String serviceActivator = ServiceActivatorComponent.class.getName() + ".handlePayload.serviceActivator";
46-
String serviceActivatorHandler = serviceActivator + ".handler";
47-
4842
assertContainsBean(context, IntegrationContextUtils.MESSAGING_ANNOTATION_POSTPROCESSOR_NAME);
4943
assertContainsBean(context, Introspector.decapitalize(MessagingAnnotationBeanPostProcessor.class.getName()));
5044

51-
assertContainsBean(context, serviceActivator);
52-
assertContainsBean(context, serviceActivatorHandler);
53-
45+
assertContainsBean(context, "inputChannel");
46+
assertContainsBean(context, "customMessageHandler");
47+
assertContainsBean(context, "customMessageHandler.serviceActivator");
48+
assertContainsBean(context, "customMessageHandler.serviceActivator.handler");
5449
}
5550
}
5651

5752
@Test
5853
void testManualEnableMessagingAnnotationsProcessing() {
5954
try (var context = createApplicationContext(true)) {
6055

61-
String serviceActivator = ServiceActivatorComponent.class.getName() + ".handlePayload.serviceActivator";
62-
String serviceActivatorHandler = serviceActivator + ".handler";
63-
6456
assertContainsBean(context, IntegrationContextUtils.MESSAGING_ANNOTATION_POSTPROCESSOR_NAME);
6557
assertContainsBean(context, Introspector.decapitalize(MessagingAnnotationBeanPostProcessor.class.getName()));
6658

67-
assertContainsBean(context, serviceActivator);
68-
assertContainsBean(context, serviceActivatorHandler);
69-
59+
assertContainsBean(context, "inputChannel");
60+
assertContainsBean(context, "customMessageHandler");
61+
assertContainsBean(context, "customMessageHandler.serviceActivator");
62+
assertContainsBean(context, "customMessageHandler.serviceActivator.handler");
7063
}
7164
}
7265

7366
@Test
7467
void testDisableMessagingAnnotationsProcessing() {
7568
try (var context = createApplicationContext(false)) {
7669

77-
String serviceActivator = ServiceActivatorComponent.class.getName() + ".handlePayload.serviceActivator";
78-
String serviceActivatorHandler = serviceActivator + ".handler";
79-
8070
assertDoesNotContainsBean(context, IntegrationContextUtils.MESSAGING_ANNOTATION_POSTPROCESSOR_NAME);
8171
assertDoesNotContainsBean(context, Introspector.decapitalize(MessagingAnnotationBeanPostProcessor.class.getName()));
8272

83-
assertDoesNotContainsBean(context, serviceActivator);
84-
assertDoesNotContainsBean(context, serviceActivatorHandler);
85-
86-
}
87-
}
88-
89-
@RetryingTest(10)
90-
void testEnableVersusDisablePerformance() {
91-
// JVM warmup
92-
try (var ctx1 = createApplicationContext(true); var ctx2 = createApplicationContext(false)) {
93-
ctx1.getApplicationName();
94-
ctx2.getApplicationName();
95-
}
96-
97-
StopWatch stopWatch = new StopWatch();
98-
99-
long enabledStartupTime;
100-
long disabledStartupTime;
101-
102-
stopWatch.start();
103-
try (var context = createApplicationContext(true)) {
104-
context.getApplicationName();
105-
106-
stopWatch.stop();
107-
108-
enabledStartupTime = stopWatch.lastTaskInfo().getTimeMillis();
109-
}
110-
111-
stopWatch.start();
112-
try (var context = createApplicationContext(false)) {
113-
context.getApplicationName();
114-
115-
stopWatch.stop();
73+
assertDoesNotContainsBean(context, "inputChannel");
74+
assertContainsBean(context, "customMessageHandler");
75+
assertDoesNotContainsBean(context, "customMessageHandler.serviceActivator");
76+
assertDoesNotContainsBean(context, "customMessageHandler.serviceActivator.handler");
11677

117-
disabledStartupTime = stopWatch.lastTaskInfo().getTimeMillis();
11878
}
119-
120-
Assertions.assertThat(enabledStartupTime).isGreaterThan(disabledStartupTime);
12179
}
12280

12381
@Configuration
12482
@EnableIntegration
125-
@Import(ServiceActivatorComponent.class)
12683
static class Config {
12784

12885
@Bean
129-
DirectChannel inputChannel() {
130-
return new DirectChannel();
131-
}
132-
133-
}
134-
135-
static class ServiceActivatorComponent {
136-
13786
@ServiceActivator(inputChannel = "inputChannel")
138-
void handlePayload(String payload) {
87+
MessageHandler customMessageHandler() {
88+
return message -> {
13989

90+
};
14091
}
14192

14293
}
14394

14495
static AnnotationConfigApplicationContext createApplicationContext(boolean enableAnnotationsProcessing) {
14596
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
14697
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context.getEnvironment(),
147-
IntegrationRegistrar.ENV_ENABLE_MESSAGING_ANNOTATIONS_PROCESSING + "=" + enableAnnotationsProcessing);
98+
"spring.integration.annotations.enable=" + enableAnnotationsProcessing);
14899

149100
context.register(Config.class);
150101
context.refresh();

src/reference/antora/modules/ROOT/pages/configuration/annotations.adoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public class FooService {
2020
}
2121
----
2222

23-
NOTE: Starting with version 7.1, the `spring.integration.annotations.enable` environment property can be used to control method-level annotation processing.
24-
By default, this property is `true`. It can be set to `false` for applications that exclusively rely on `IntegrationFlow` definitions.
23+
NOTE: Starting with version 7.1, the `spring.integration.annotations.enable` property in the Spring environment can be used to control method-level annotations processing. By default, this property is `true`. It can be set to `false` to disable messaging annotations processing.
2524

2625
Exactly what it means for the method to "`handle`" the Message depends on the particular annotation.
2726
Annotations available in Spring Integration include:

src/reference/antora/modules/ROOT/pages/whats-new.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ See xref:grpc.adoc[] for more information.
3535
The `MessageTransformingHandler.requiresReply` flag cannot be modified: an `UnsupportedOperationException` is thrown from the overridden `setRequiresReply()` method to indicate the transformer pattern cannot produce nulls for replies.
3636
See xref:transformer.adoc[] for more information.
3737

38-
A new `spring.integration.annotations.enable` environment property is introduced to control method-level annotation processing. Setting this property to `false` optimizes startup performance for applications that exclusively rely on `IntegrationFlow` definitions.
38+
A new `spring.integration.annotations.enable` property is introduced to control method-level annotations processing.
3939
See xref:configuration/annotations.adoc[] for more information.
4040

4141
[[x7.1-web-services-changes]]

0 commit comments

Comments
 (0)