INT-3327: Add IntegrationConverter Annotation

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

INT-3327: Addressing PR comments

Polishing
This commit is contained in:
Artem Bilan
2014-03-31 16:38:28 +03:00
committed by Gary Russell
parent d74b4dba73
commit 969310b453
14 changed files with 317 additions and 138 deletions

View File

@@ -588,10 +588,12 @@ any transaction configuration essentially allowing you to enhance the behavior o
In this scenario we need to perform type conversion. Spring Integration provides a convenient way for registering type
converters (using the Spring 3.x ConversionService) within its own instance of a conversion service bean named
<emphasis>integrationConversionService</emphasis>.
That bean is automatically created as soon as the first converter is defined using the Spring Integration namespace support.
That bean is automatically created as soon as the first converter is defined using the Spring Integration infrastructure.
To register a Converter all you need is to implement
<interfacename>org.springframework.core.convert.converter.Converter</interfacename> and define it via
<interfacename>org.springframework.core.convert.converter.Converter</interfacename>,
<interfacename>org.springframework.core.convert.converter.GenericConverter</interfacename> or
<interfacename>org.springframework.core.convert.converter.ConverterFactory</interfacename> and define it via
convenient namespace support:
<programlisting language="xml"><![CDATA[<int:converter ref="sampleConverter"/>
@@ -602,6 +604,31 @@ any transaction configuration essentially allowing you to enhance the behavior o
<bean class="o.s.i.config.xml.ConverterParserTests$TestConverter3"/>
</int:converter>]]></programlisting>
</para>
<para>
Starting with <emphasis>Spring Integration 4.0</emphasis>, the above configuration is available using annotations:
<programlisting language="java"><![CDATA[@Component
@IntegrationConverter
public class TestConverter implements Converter<Boolean, Number> {
public Number convert(Boolean source) {
return source ? 1 : 0;
}
}]]></programlisting>
or as a <code>@Configuration</code> part:
<programlisting language="java"><![CDATA[@Configuration
@EnableIntegration
public class ContextConfiguration {
@Bean
@IntegrationConverter
public SerializingConverter serializingConverter() {
return new SerializingConverter();
}
}]]></programlisting>
</para>
<important>
<para>
When configuring an <emphasis>Application Context</emphasis>, the

View File

@@ -368,6 +368,15 @@
on <classname>@Bean</classname> methods within <classname>@Configuration</classname> classes. In either case,
the bean <emphasis role="bold">must</emphasis> be a <interfacename>ChannelInterceptor</interfacename>.
</para>
<para>
The <classname>@IntegrationConverter</classname> annotation has been introduced to
mark <interfacename>Converter</interfacename>, <interfacename>GenericConverter</interfacename> or
<interfacename>ConverterFactory</interfacename> beans as candidate converters for <code>integrationConversionService</code>.
This annotation is an analogue of the <code>&lt;int:converter&gt;</code> xml element
(see <xref linkend="payload-type-conversion"/>). <code>@IntegrationConverter</code> annotations
can be placed at the class level (with a <classname>@Component</classname> stereotype annotation), or
on <classname>@Bean</classname> methods within <classname>@Configuration</classname> classes.
</para>
</section>
</chapter>

View File

@@ -56,7 +56,7 @@
<title>@MessagingGateway</title>
<para>
Messaging gateway interfaces can now be configured with the <code>@MessagingGateway</code> annotation.
It is an analogue of the <code>&lt;gateway/&gt;</code> xml element.
It is an analogue of the <code>&lt;int:gateway/&gt;</code> xml element.
For more information, see <xref linkend="messaging-gateway-annotation"/>.
</para>
</section>
@@ -68,7 +68,7 @@
Spring Integration infrastructure beans to be configured using Spring Boot's
<code>@EnableAutoConfiguration</code>.
For more information see
<ulink url="http://projects.spring.io/spring-boot/docs/spring-boot-autoconfigure/README.html"
<ulink url="http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-auto-configuration.html"
>Spring Boot - AutoConfigure</ulink>.
</para>
</section>
@@ -80,6 +80,14 @@
For more information, see <xref linkend="enable-integration"/>.
</para>
</section>
<section id="4.0-integration-converter">
<title>@IntegrationConverter</title>
<para>
The <code>@IntegrationConverter</code> annotation has bean introduced,
as an analogue of <code>&lt;int:converter/&gt;</code> component.
For more information, see <xref linkend="enable-integration"/>.
</para>
</section>
<section id="4.0-enable-publisher">
<title>@EnablePublisher</title>
<para>