INT-4051: Add PublisherAnnBPP when @EnableInt

JIRA: https://jira.spring.io/browse/INT-4051

Previously we can process `@Publisher` annotations only with the `<int:annotation-config>` or with an explicit `@EnablePublisher("")`

* Fix `PublisherRegistrar` to relax from the fact if we have `@EnablePublisher` or not and register `PublisherAnnotationBeanPostProcessor` without `defaultChannelName`
This commit is contained in:
Artem Bilan
2016-06-09 18:00:27 -04:00
committed by Marius Bogoevici
parent dbd034c17a
commit cabe507e0e
3 changed files with 22 additions and 5 deletions

View File

@@ -82,7 +82,6 @@ public class PublisherAnnotationBeanPostProcessor extends ProxyConfig
return this.order;
}
@SuppressWarnings("deprecation")
@Override
public void afterPropertiesSet() {
this.advisor = new PublisherAnnotationAdvisor();

View File

@@ -28,6 +28,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.integration.aop.PublisherAnnotationBeanPostProcessor;
import org.springframework.integration.context.IntegrationContextUtils;
@@ -46,10 +47,10 @@ public class PublisherRegistrar implements ImportBeanDefinitionRegistrar {
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
Map<String, Object> annotationAttributes =
importingClassMetadata.getAnnotationAttributes(EnablePublisher.class.getName());
if (annotationAttributes == null) {
return;
}
String value = (String) annotationAttributes.get("value");
String value = (annotationAttributes == null
? (String) AnnotationUtils.getDefaultValue(EnablePublisher.class)
: (String) annotationAttributes.get("value"));
if (!registry.containsBeanDefinition(IntegrationContextUtils.PUBLISHER_ANNOTATION_POSTPROCESSOR_NAME)) {
BeanDefinitionBuilder builder =
BeanDefinitionBuilder.genericBeanDefinition(PublisherAnnotationBeanPostProcessor.class)

View File

@@ -48,6 +48,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.Poller;
import org.springframework.integration.annotation.Publisher;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.QueueChannel;
@@ -60,6 +61,7 @@ import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -67,6 +69,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Gary Russell
* @author Artem Bilan
* @since 4.2
*
*/
@@ -84,6 +87,9 @@ public class BarrierMessageHandlerTests {
@Autowired
private MessageChannel release;
@Autowired
private PollableChannel publisherChannel;
@Test
public void testRequestBeforeReply() throws Exception {
final BarrierMessageHandler handler = new BarrierMessageHandler(10000);
@@ -256,6 +262,10 @@ public class BarrierMessageHandlerTests {
Message<?> out = this.out.receive(10000);
assertNotNull(out);
assertEquals("[foo, bar]", out.getPayload().toString());
Message<?> publisherMessage = this.publisherChannel.receive(10000);
assertNotNull(publisherMessage);
assertEquals("BAR", publisherMessage.getPayload());
}
@Configuration
@@ -277,6 +287,11 @@ public class BarrierMessageHandlerTests {
return new QueueChannel();
}
@Bean
public PollableChannel publisherChannel() {
return new QueueChannel();
}
@ServiceActivator(inputChannel = "in")
@Bean
public BarrierMessageHandler barrier() {
@@ -291,6 +306,8 @@ public class BarrierMessageHandlerTests {
return new MessageHandler() {
@Override
@Publisher(channel = "publisherChannel")
@Payload("#args[0].payload.toUpperCase()")
public void handleMessage(Message<?> message) throws MessagingException {
barrier().trigger(message);
}