INT-4488: Require @EnablePublisher
JIRA: https://jira.spring.io/browse/INT-4488 Since `PublisherAnnotationBeanPostProcessor` is quite expensive (1.5x the CPU used by `MessagingAnnotationPostProcessor` in a simple application) * So not register a `PublisherAnnotationBeanPostProcessor` by default. The `@EnablePublisher` has to be presented on the `@Configuration` to allow the `@Publisher` AOP * Change the `<int:annotation-config>` to require a new `<int:enable-publisher>` sub-element for similar purpose - do not register `PublisherAnnotationBeanPostProcessor` by default
This commit is contained in:
committed by
Gary Russell
parent
13510df575
commit
69af967c78
@@ -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.
|
||||
* <p>
|
||||
* 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 "";
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<String, Object> getAnnotationAttributes(String annotationType) {
|
||||
return Collections.<String, Object>singletonMap("value", element.getAttribute("default-publisher-channel"));
|
||||
}
|
||||
}, parserContext.getRegistry());
|
||||
StandardAnnotationMetadata importingClassMetadata =
|
||||
new StandardAnnotationMetadata(Object.class) {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> 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;
|
||||
}
|
||||
|
||||
@@ -20,18 +20,24 @@
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="default-publisher-channel" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Default output channel for the @Publisher annotation support.
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.messaging.MessageChannel" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="enable-publisher" minOccurs="0">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="default-publisher-channel" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Default output channel for the @Publisher annotation support.
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.messaging.MessageChannel" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
@@ -53,22 +59,22 @@
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="before-commit" minOccurs="0" maxOccurs="1">
|
||||
<xsd:complexType>
|
||||
<xsd:attributeGroup ref="synchronizationAttributeGroup"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="after-commit" minOccurs="0" maxOccurs="1">
|
||||
<xsd:complexType>
|
||||
<xsd:attributeGroup ref="synchronizationAttributeGroup"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="after-rollback" minOccurs="0" maxOccurs="1">
|
||||
<xsd:complexType>
|
||||
<xsd:attributeGroup ref="synchronizationAttributeGroup"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
<xsd:element name="before-commit" minOccurs="0" maxOccurs="1">
|
||||
<xsd:complexType>
|
||||
<xsd:attributeGroup ref="synchronizationAttributeGroup"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="after-commit" minOccurs="0" maxOccurs="1">
|
||||
<xsd:complexType>
|
||||
<xsd:attributeGroup ref="synchronizationAttributeGroup"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="after-rollback" minOccurs="0" maxOccurs="1">
|
||||
<xsd:complexType>
|
||||
<xsd:attributeGroup ref="synchronizationAttributeGroup"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="id" type="xsd:string" use="required"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
@@ -134,7 +140,7 @@
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a Point-to-Point MessageChannel.
|
||||
See 'PointToPointChannelParser' source code for 'MessageChannel' implementaitons.
|
||||
See 'PointToPointChannelParser' source code for 'MessageChannel' implementations.
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd"
|
||||
xmlns:si="http://www.springframework.org/schema/integration">
|
||||
|
||||
@@ -17,6 +15,8 @@
|
||||
<si:queue />
|
||||
</si:channel>
|
||||
|
||||
<si:annotation-config default-publisher-channel="defaultChannel"/>
|
||||
<si:annotation-config>
|
||||
<si:enable-publisher default-publisher-channel="defaultChannel"/>
|
||||
</si:annotation-config>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
|
||||
<message-history tracked-components="publishedChannel,input,annotationTestService*"/>
|
||||
|
||||
<annotation-config default-publisher-channel="publishedChannel"/>
|
||||
<annotation-config>
|
||||
<enable-publisher default-publisher-channel="publishedChannel"/>
|
||||
</annotation-config>
|
||||
|
||||
<channel-interceptor pattern="none">
|
||||
<wire-tap channel="bar" />
|
||||
|
||||
Reference in New Issue
Block a user