'Spring Integration using DirectChannel in IntegrationFlow throws "Dispatcher has no subscribers"

I have this very basic setup of IntegrationFlow with Spring Integration Java DSL:

@IntegrationComponentScan
@EnableIntegration
@Configuration
public class DummyConfig {

    @MessagingGateway
    public interface DummyGateway {
        @Gateway(requestChannel = "dummyInChannel")
        void echo(String payload);
    }

    @Bean(name = "dummyInChannel")
    public MessageChannel dummyInChannel() {
        return MessageChannels.direct().get();
    }

    @Bean
    public IntegrationFlow dummyFlow() {
        return IntegrationFlows.from(dummyInChannel())
            .handle(String.class, (payload, headers) -> {
                System.out.println(payload);
                return "";
            })
            .get();
    }

}

When I try to post a message to my gateway

dummyGateway.echo("test");

I'm getting and exception:

Caused by: org.springframework.messaging.MessageDeliveryException: 
Dispatcher has no subscribers for channel 'application.dummyInChannel'.; nested exception 
is org.springframework.integration.MessageDispatchingException: Dispatcher 
has no subscribers, failedMessage=GenericMessage [payload=test, 
headers={replyChannel=nullChannel, id=6e4302e4-95f0-bf5a-c1a3-e8cd587c23fb, timestamp=1643269549272}]

I thought, that doing .handle() in my flow is exactly subscribing to a channel. Then, why am I getting this exception? How to properly subscribe to my channel in this scenario?



Solution 1:[1]

public static void main(String[] args) {
        SpringApplication application = new SpringApplication(DummyConfig.class);
        ConfigurableApplicationContext ctx = application.run(args);
         ctx.getBean(DummyGateway.class).echo("MyAwesomeString");
        ctx.close();
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Petr