IntegrationFlow: optional @MessagingGateway

When we use `IntegrationFlows.from(Class<?>)`, we don't need to require
present for `@MessagingGateway`, we can just synthesize it with the
default properties

This way we can simply make gateway proxies for the `java.util.function`
interfaces which should be useful for Spring Cloud Function
This commit is contained in:
Artem Bilan
2017-07-20 17:54:12 -04:00
parent d4a99919ed
commit 5a66854c67
3 changed files with 15 additions and 17 deletions

View File

@@ -274,7 +274,7 @@ public final class IntegrationFlows {
* on the provided service interface.
* <p>A gateway proxy bean for provided service interface is registered under a name of
* the {@link IntegrationFlow} bean plus {@code .gateway} suffix.
* @param serviceInterface the class with a
* @param serviceInterface the service interface class with an optional
* {@link org.springframework.integration.annotation.MessagingGateway} annotation.
* @return new {@link IntegrationFlowBuilder}.
*/

View File

@@ -23,6 +23,7 @@ import java.util.concurrent.Executor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.expression.Expression;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.integration.annotation.AnnotationConstants;
@@ -32,8 +33,9 @@ import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/**
* A {@link GatewayProxyFactoryBean} extension for Java configuration,
* when service interface is marked with the {@link MessagingGateway} annotation.
* A {@link GatewayProxyFactoryBean} extension for Java configuration.
* The service interface may be marked with the {@link MessagingGateway} annotation.
* Otherwise the default state is applied.
*
* @author Artem Bilan
*
@@ -45,11 +47,13 @@ public class AnnotationGatewayProxyFactoryBean extends GatewayProxyFactoryBean {
public AnnotationGatewayProxyFactoryBean(Class<?> serviceInterface) {
super(serviceInterface);
this.gatewayAttributes = AnnotatedElementUtils.getMergedAnnotationAttributes(serviceInterface,
AnnotationAttributes gatewayAttributes = AnnotatedElementUtils.getMergedAnnotationAttributes(serviceInterface,
MessagingGateway.class.getName(), false, true);
Assert.notNull(this.gatewayAttributes,
"The Messaging Gateway interface must be annotated with the @MessagingGateway");
if (gatewayAttributes == null) {
gatewayAttributes = AnnotationUtils.getAnnotationAttributes(
AnnotationUtils.synthesizeAnnotation(MessagingGateway.class), false, true);
}
this.gatewayAttributes = gatewayAttributes;
}
@Override