Duplicate @StreamListener exception when Implementing an interface
using:
- spring-boot-starter-parent 1.4.1.RELEASE;
- spring-cloud-dependencies Camden.RELEASE
- spring-cloud-stream-dependencies 1.0.3.RELEASE
- spring-cloud-starter-stream-rabbit
Given that I have the following interfaces:
public interface Iceberg {
String INPUT = "input";
@Input(Iceberg.INPUT)
SubscribableChannel input();
}
public interface ISink {
void sighted(String msg);
}
And the following implementation:
@EnableBinding(Iceberg.class)
public class Titanic implements ISink {
@Override
@StreamListener(Iceberg.INPUT)
public void sighted(String msg) {
System.out.println("Oh no! " + msg);
}
Then I get org.springframework.beans.factory.BeanInitializationException: Duplicate @StreamListener mapping for 'input' on Titanic#sighted[1 args] already existing for Titanic#sighted[1 args]
But I should see on the console "Oh no! Iceberg sighted" when I send "Iceberg sighted".
Depends what your Iceberg interface is. Do you have another @EnableBinding or a @StreamListener in your application ?
I noticed that your component is both a configuration class (@EnableBinding is meta-annotated with @Configuration) and a bean. I would suggest separating the configuration from the bean definition
@EnableBinding(Iceberg.class) // move this from Titanic.class
public class TitanicConfiguration {
@Bean
public ISink titanic() {
result new Titanic();
}
}
@mbogoevici Oh, that might be it. I was following a tutorial in which they're all under a single SpringBootApplication main class.
@mbogoevici nevermind, that wasn't it. Separating them doesn't work. Furthermore, If I remove the interface ISink and the @Override annotation, it works.
@TarekSaid Could you check what is different between your project and
https://github.com/mbogoevici/gh-issues/tree/master/gh-683 ?
I've tried to reproduce this issue, but can't. Thanks!
@mbogoevici hey, I guess what's different in my case is that it's a multi-maven project. Check out the repository https://github.com/TarekSaid/co.synergyspace, specifically the projects posts-api and posts-impl, interface IBusinessConsumer and class BusinessConsumer. If you remove the implementation or switch to @ServiceActivator(inputChannel = Sink.INPUT), it should clean, run the integration tests and install.
Ok, thanks - I'll take a look. Seems like your project is indeed creating duplicate subscriptions on the input channel, but can't tell exactly what until I build this locally.
@mbogoevici Hi, I haven't debugged the code so I don't know what's the root cause of the problem, but it seems it has to do with implementing a generic interface (such as public interface IBusinessConsumer<T extends Business>).
After I removed the generic parameter from the interface, it started working.