Add @IntegrationComponentScan auto-configuration
Update Spring Integration auto-configuration so that `@IntegrationComponentScan` from `AutoConfigurationPackages` is implicitly applied. Prior to this commit `@MessagingGateway` interfaces would only get picked up if `@IntegrationComponentScan` was added alongside with the `@SpringBootApplication`. Fixes gh-2037 Closes gh-7718
This commit is contained in:
committed by
Phillip Webb
parent
02917ff00a
commit
a79f71cbe8
@@ -30,6 +30,9 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.integration.annotation.IntegrationComponentScan;
|
||||
import org.springframework.integration.annotation.MessagingGateway;
|
||||
import org.springframework.integration.gateway.RequestReplyExchanger;
|
||||
import org.springframework.integration.support.channel.HeaderChannelRegistry;
|
||||
import org.springframework.integration.support.management.IntegrationManagementConfigurer;
|
||||
import org.springframework.jmx.export.MBeanExporter;
|
||||
@@ -61,24 +64,34 @@ public class IntegrationAutoConfigurationTests {
|
||||
@Test
|
||||
public void integrationIsAvailable() {
|
||||
load();
|
||||
assertThat(this.context.getBean(HeaderChannelRegistry.class)).isNotNull();
|
||||
assertThat(this.context.getBean(TestGateway.class)).isNotNull();
|
||||
assertThat(this.context.getBean(IntegrationAutoConfiguration.IntegrationComponentScanAutoConfiguration.class))
|
||||
.isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitIntegrationComponentScan() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(IntegrationComponentScanConfiguration.class,
|
||||
JmxAutoConfiguration.class,
|
||||
IntegrationAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBean(TestGateway.class)).isNotNull();
|
||||
assertThat(this.context.getBeansOfType(IntegrationAutoConfiguration.IntegrationComponentScanAutoConfiguration.class))
|
||||
.isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parentContext() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(JmxAutoConfiguration.class,
|
||||
IntegrationAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
load();
|
||||
AnnotationConfigApplicationContext parent = this.context;
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.setParent(parent);
|
||||
this.context.register(JmxAutoConfiguration.class,
|
||||
IntegrationAutoConfiguration.class);
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "SPRING_JMX_DEFAULT_DOMAIN=org.foo");
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBean(HeaderChannelRegistry.class)).isNotNull();
|
||||
((ConfigurableApplicationContext) this.context.getParent()).close();
|
||||
this.context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -151,4 +164,15 @@ public class IntegrationAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@IntegrationComponentScan
|
||||
static class IntegrationComponentScanConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@MessagingGateway
|
||||
public interface TestGateway extends RequestReplyExchanger {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user