INT-3829: Honor @Profile on Messaging @Beans
JIRA: https://jira.spring.io/browse/INT-3829 Alongside with the `@Bean` definition we can use, for example, `@Profile` `@Conditional` annotation. And the final bean won't be populated to the context. When messaging annotations are present on `@Bean`s, a second bean for the endpoint consumer is created. Previously, the `MessagingAnnotationPostProcessor` did not check if the `@Bean` was present; hence we ended up with a `NoSuchBeanDefinitionException` * Add appropriate `try...catch(NoSuchBeanDefinitionException)` to the `AbstractMethodAnnotationPostProcessor` and `InboundChannelAdapterAnnotationPostProcessor` to skip further endpoint processing if the bean does not exist. Add DEBUG message for the skipped beans Polishing
This commit is contained in:
committed by
Gary Russell
parent
a9f50d32e4
commit
c23aa70ec8
@@ -16,7 +16,7 @@ Direct usage of the API is of course always an option, but we expect that most u
|
||||
=== Namespace Support
|
||||
|
||||
Spring Integration components can be configured with XML elements that map directly to the terminology and concepts of enterprise integration.
|
||||
In many cases, the element names match those of thehttp://www.eaipatterns.com[Enterprise Integration Patterns].
|
||||
In many cases, the element names match those of the http://www.eaipatterns.com[Enterprise Integration Patterns].
|
||||
|
||||
To enable Spring Integration's core namespace support within your Spring configuration files, add the following namespace reference and schema mapping in your top-level 'beans' element:
|
||||
|
||||
@@ -532,6 +532,20 @@ For example the endpoint (`SourcePollingChannelAdapter`) for the `consoleSource(
|
||||
|
||||
IMPORTANT: When using these annotations on `@Bean` definitions, the `inputChannel` must reference a declared bean; channels are not automatically declared in this case.
|
||||
|
||||
NOTE: With Java & Annotation configuration we can use any `@Conditional` (e.g. `@Profile`) definition on the `@Bean`
|
||||
method level, meaning to skip the bean registration by some condition reason:
|
||||
[source,java]
|
||||
----
|
||||
@Bean
|
||||
@ServiceActivator(inputChannel = "skippedChannel")
|
||||
@Profile("foo")
|
||||
public MessageHandler skipped() {
|
||||
return System.out::println;
|
||||
}
|
||||
----
|
||||
Together with the existing Spring Container logic, the Messaging Endpoint bean, based on the `@ServiceActivator`
|
||||
annotation, won't be registered as well.
|
||||
|
||||
==== Creating a Bridge with Annotations
|
||||
|
||||
Starting with _version 4.0_, the Messaging Annotation and Java configuration provides `@BridgeFrom` and `@BridgeTo` `@Bean` method annotations to mark `MessageChannel` beans in `@Configuration` classes.
|
||||
|
||||
Reference in New Issue
Block a user