diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/EnablePublisher.java b/spring-integration-core/src/main/java/org/springframework/integration/config/EnablePublisher.java index 2f0db8a10d..f949d0fc70 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/EnablePublisher.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/EnablePublisher.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,12 +27,10 @@ import org.springframework.context.annotation.Import; /** * Provides the registration for the {@link org.springframework.integration.aop.PublisherAnnotationBeanPostProcessor} * to allow the use of the {@link org.springframework.integration.annotation.Publisher} annotation. - * In addition the {@code default-publisher-channel} name has to be configured as the {@code value} of this annotation. - *

- * Note: the {@link org.springframework.integration.annotation.Publisher} annotation is enabled by default via - * {@link EnableIntegration} processing, but there is no hook to configure the {@code default-publisher-channel}. + * In addition the {@code default-publisher-channel} name can be configured as the {@code value} of this annotation. * * @author Artem Bilan + * * @since 4.0 */ @Target(ElementType.TYPE) @@ -44,5 +42,5 @@ public @interface EnablePublisher { /** * @return the {@code default-publisher-channel} name. */ - String value(); + String value() default ""; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationRegistrar.java b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationRegistrar.java index 4fa0a937d1..d0b7ecf7fa 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationRegistrar.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationRegistrar.java @@ -391,7 +391,10 @@ public class IntegrationRegistrar implements ImportBeanDefinitionRegistrar, Bean builder.getBeanDefinition()); } - new PublisherRegistrar().registerBeanDefinitions(meta, registry); + if (meta.getAnnotationAttributes(EnablePublisher.class.getName()) != null) { + new PublisherRegistrar(). + registerBeanDefinitions(meta, registry); + } } /** @@ -399,7 +402,9 @@ public class IntegrationRegistrar implements ImportBeanDefinitionRegistrar, Bean * to process the external Integration infrastructure. */ private void registerIntegrationConfigurationBeanFactoryPostProcessor(BeanDefinitionRegistry registry) { - if (!registry.containsBeanDefinition(IntegrationContextUtils.INTEGRATION_CONFIGURATION_POST_PROCESSOR_BEAN_NAME)) { + if (!registry.containsBeanDefinition( + IntegrationContextUtils.INTEGRATION_CONFIGURATION_POST_PROCESSOR_BEAN_NAME)) { + BeanDefinitionBuilder postProcessorBuilder = BeanDefinitionBuilder .genericBeanDefinition(IntegrationConfigurationBeanFactoryPostProcessor.class) .setRole(BeanDefinition.ROLE_INFRASTRUCTURE); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AnnotationConfigParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AnnotationConfigParser.java index 709178f574..51263e3d50 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AnnotationConfigParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AnnotationConfigParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,9 @@ import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.core.type.StandardAnnotationMetadata; +import org.springframework.integration.config.EnablePublisher; import org.springframework.integration.config.IntegrationRegistrar; +import org.springframework.util.xml.DomUtils; /** * Parser for the <annotation-config> element of the integration namespace. @@ -38,13 +40,33 @@ public class AnnotationConfigParser implements BeanDefinitionParser { @Override public BeanDefinition parse(final Element element, ParserContext parserContext) { - new IntegrationRegistrar().registerBeanDefinitions(new StandardAnnotationMetadata(Object.class) { + IntegrationRegistrar integrationRegistrar = new IntegrationRegistrar(); + integrationRegistrar.setBeanClassLoader(parserContext.getReaderContext().getBeanClassLoader()); - @Override - public Map getAnnotationAttributes(String annotationType) { - return Collections.singletonMap("value", element.getAttribute("default-publisher-channel")); - } - }, parserContext.getRegistry()); + StandardAnnotationMetadata importingClassMetadata = + new StandardAnnotationMetadata(Object.class) { + + @Override + public Map getAnnotationAttributes(String annotationType) { + if (EnablePublisher.class.getName().equals(annotationType)) { + Element enablePublisherElement = + DomUtils.getChildElementByTagName(element, "enable-publisher"); + if (enablePublisherElement != null) { + return Collections.singletonMap("value", + enablePublisherElement.getAttribute("default-publisher-channel")); + } + else { + return null; + } + } + else { + return null; + } + } + + }; + + integrationRegistrar.registerBeanDefinitions(importingClassMetadata, parserContext.getRegistry()); return null; } diff --git a/spring-integration-core/src/main/resources/org/springframework/integration/config/spring-integration-5.1.xsd b/spring-integration-core/src/main/resources/org/springframework/integration/config/spring-integration-5.1.xsd index f739d55209..440c840177 100644 --- a/spring-integration-core/src/main/resources/org/springframework/integration/config/spring-integration-5.1.xsd +++ b/spring-integration-core/src/main/resources/org/springframework/integration/config/spring-integration-5.1.xsd @@ -20,18 +20,24 @@ - - - - Default output channel for the @Publisher annotation support. - - - - - - - - + + + + + + + Default output channel for the @Publisher annotation support. + + + + + + + + + + + @@ -53,22 +59,22 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -134,7 +140,7 @@ Defines a Point-to-Point MessageChannel. - See 'PointToPointChannelParser' source code for 'MessageChannel' implementaitons. + See 'PointToPointChannelParser' source code for 'MessageChannel' implementations. diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/BarrierMessageHandlerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/BarrierMessageHandlerTests.java index 9100003dac..6e20fc7436 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/BarrierMessageHandlerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/BarrierMessageHandlerTests.java @@ -55,6 +55,7 @@ import org.springframework.integration.annotation.ServiceActivator; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.config.EnableIntegration; +import org.springframework.integration.config.EnablePublisher; import org.springframework.integration.handler.ReplyRequiredException; import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.test.util.TestUtils; @@ -72,6 +73,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Gary Russell * @author Artem Bilan + * * @since 4.2 * */ @@ -263,6 +265,7 @@ public class BarrierMessageHandlerTests { @Configuration @EnableIntegration + @EnablePublisher public static class Config { @Bean diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aop/AnnotationConfigRegistrationTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/aop/AnnotationConfigRegistrationTests-context.xml index 4b536159a1..4147e6b05e 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aop/AnnotationConfigRegistrationTests-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/aop/AnnotationConfigRegistrationTests-context.xml @@ -1,9 +1,7 @@ @@ -17,6 +15,8 @@ - + + + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/configuration/EnableIntegrationTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/configuration/EnableIntegrationTests-context.xml index 8f990e3264..00bde4e2ec 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/configuration/EnableIntegrationTests-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/configuration/EnableIntegrationTests-context.xml @@ -14,7 +14,9 @@ - + + + diff --git a/src/reference/asciidoc/message-publishing.adoc b/src/reference/asciidoc/message-publishing.adoc index 7e561337de..d52bb3384f 100644 --- a/src/reference/asciidoc/message-publishing.adoc +++ b/src/reference/asciidoc/message-publishing.adoc @@ -15,6 +15,8 @@ Spring Integration provides two approaches: XML and Annotation-driven. ==== Annotation-driven approach via @Publisher annotation The annotation-driven approach allows you to annotate any method with the `@Publisher` annotation, specifying a 'channel' attribute. +Starting with _version 5.1_, to switch this functionality on, the `@EnablePublisher` annotation must be provided on some `@Configuration` class. +See <> for more information. The Message will be constructed from the return value of the method invocation and sent to a channel specified by the 'channel' attribute. To further manage message structure, you can also use a combination of both `@Payload` and `@Header` annotations. @@ -105,10 +107,24 @@ As with most other annotation-driven features in Spring, you will need to regist You can instead use namespace support for a more concise configuration: [source,xml] ---- - + + + ---- -Similar to other Spring annotations (@Component, @Scheduled, etc.), `@Publisher` can also be used as a meta-annotation. +For Java & Annotation Spring configuration, the `@EnablePublisher` annotation must be used: + +[source,java] +---- +@Configuration +@EnableIntegration +@EnablePublisher("defaultChannel") +public class IntegrationConfiguration { + ... +} +---- + +Similar to other Spring annotations (`@Component`, `@Scheduled`, etc.), `@Publisher` can also be used as a meta-annotation. That means you can define your own annotations that will be treated in the same way as the `@Publisher` itself. [source,java] diff --git a/src/reference/asciidoc/whats-new.adoc b/src/reference/asciidoc/whats-new.adoc index 6a306afef3..e323161fd0 100644 --- a/src/reference/asciidoc/whats-new.adoc +++ b/src/reference/asciidoc/whats-new.adoc @@ -51,7 +51,20 @@ Starting with _version 5.0.5_, generated bean names for the components in an `In See <> for more information. -==== AMQP Changes +==== Aggregator Changes + +An aggregator now expires the group immediately, if the `groupTimeout` is evaluated to a negative value. +Only `null` is considered as a signal do nothing for the current message. + +See <> for more information. + +==== @Publisher annotation changes + +Starting with _version 5.1, the `@Publisher` AOP functionality has to be turned on explicitly via `@EnablePublisher` or via `` sub-element on the ``. + +See <> for more information. + +=== AMQP Changes `ID` and `Timestamp` header mapping changes in the `DefaultAmqpHeaderMapper`. See the note near the bottom of <> for more information. @@ -59,15 +72,8 @@ See the note near the bottom of <> for more information. The `contentType` header is no longer incorrectly mapped as an entry in the general headers map. See <> for more information. -==== JDBC Changes +=== JDBC Changes A confusing `max-rows-per-poll` property on the JDBC Inbound Channel Adapter and JDBC Outbound Gateway has been deprecated in favor newly introduced `max-rows` property. See <> for more information. - -==== Aggregator Changes - -An aggregator now expires the group immediately, if the `groupTimeout` is evaluated to a negative value. -Only `null` is considered as a signal do nothing for the current message. - -See <> for more information.