@Profile不适用于消息网关



在我的集成应用程序中,我定义了一个简单的网关如下:

@MessagingGateway
@Profile(value = { "export" })
public interface ExportingOutboundGateway {
@Gateway(requestChannel = "exportChannel")
void send(RequestInfo request);
}

如果我使用application.properties中声明的Spring.profiles.active=export执行这个Spring引导应用程序,则无法创建网关bean

网关bean的定义有什么错误吗?如何修复?

这是IntegrationComponentScanRegistrar中的一个错误。当我们扫描@MessagingGateway接口时,我们不接受应用程序上下文中的Environment,而内部ClassPathScanningCandidateComponentProvider只使用默认接口,而我们没有活动配置文件。

作为一种变通方法,我建议这样做:

@Bean
@Profile("export")
public AnnotationGatewayProxyFactoryBean exportingOutboundGateway() {
return new AnnotationGatewayProxyFactoryBean(ExportingOutboundGateway.class);
}
...
public interface ExportingOutboundGateway {
@Gateway(requestChannel = "exportChannel")
void send(String request);
}

关于此事的JIRA:https://jira.spring.io/browse/INT-4565

最新更新