org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name ‘message_input’ defined in com.exapi.exapi.message.StreamClient: bean definition with this name already exists - Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=com.exapi.exapi.message.StreamClient; factoryMethodName=input; initMethodName=null; destroyMethodName=null
at org.springframework.cloud.stream.binding.BindingBeanDefinitionRegistryUtils.registerBindingTargetBeanDefinition(BindingBeanDefinitionRegistryUtils.java:68) ~[spring-cloud-stream-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.cloud.stream.binding.BindingBeanDefinitionRegistryUtils.registerOutputBindingTargetBeanDefinition(BindingBeanDefinitionRegistryUtils.java:55) ~[spring-cloud-stream-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.cloud.stream.binding.BindingBeanDefinitionRegistryUtils.lambda$registerBindingTargetBeanDefinitions
0
(
B
i
n
d
i
n
g
B
e
a
n
D
e
f
i
n
i
t
i
o
n
R
e
g
i
s
t
r
y
U
t
i
l
s
.
j
a
v
a
:
92
)
[
s
p
r
i
n
g
−
c
l
o
u
d
−
s
t
r
e
a
m
−
2.1.2.
R
E
L
E
A
S
E
.
j
a
r
:
2.1.2.
R
E
L
E
A
S
E
]
a
t
o
r
g
.
s
p
r
i
n
g
f
r
a
m
e
w
o
r
k
.
u
t
i
l
.
R
e
f
l
e
c
t
i
o
n
U
t
i
l
s
.
d
o
W
i
t
h
M
e
t
h
o
d
s
(
R
e
f
l
e
c
t
i
o
n
U
t
i
l
s
.
j
a
v
a
:
589
)
[
s
p
r
i
n
g
−
c
o
r
e
−
5.1.5.
R
E
L
E
A
S
E
.
j
a
r
:
5.1.5.
R
E
L
E
A
S
E
]
a
t
o
r
g
.
s
p
r
i
n
g
f
r
a
m
e
w
o
r
k
.
u
t
i
l
.
R
e
f
l
e
c
t
i
o
n
U
t
i
l
s
.
d
o
W
i
t
h
M
e
t
h
o
d
s
(
R
e
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a
m
b
d
a
0(BindingBeanDefinitionRegistryUtils.java:92) ~[spring-cloud-stream-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:589) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:568) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.cloud.stream.binding.BindingBeanDefinitionRegistryUtils.registerBindingTargetBeanDefinitions(BindingBeanDefinitionRegistryUtils.java:82) ~[spring-cloud-stream-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.cloud.stream.config.BindingBeansRegistrar.registerBeanDefinitions(BindingBeansRegistrar.java:44) ~[spring-cloud-stream-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.lambda
0(BindingBeanDefinitionRegistryUtils.java:92) [spring−cloud−stream−2.1.2.RELEASE.jar:2.1.2.RELEASE]atorg.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:589) [spring−core−5.1.5.RELEASE.jar:5.1.5.RELEASE]atorg.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:568) [spring−core−5.1.5.RELEASE.jar:5.1.5.RELEASE]atorg.springframework.cloud.stream.binding.BindingBeanDefinitionRegistryUtils.registerBindingTargetBeanDefinitions(BindingBeanDefinitionRegistryUtils.java:82) [spring−cloud−stream−2.1.2.RELEASE.jar:2.1.2.RELEASE]atorg.springframework.cloud.stream.config.BindingBeansRegistrar.registerBeanDefinitions(BindingBeansRegistrar.java:44) [spring−cloud−stream−2.1.2.RELEASE.jar:2.1.2.RELEASE]atorg.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.lambdaloadBeanDefinitionsFromRegistrars$1(ConfigurationClassBeanDefinitionReader.java:364) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684) ~[na:1.8.0_181]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:363) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:145) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:117) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:327) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:705) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
这是由于同一个服务的信道中名字重复了,需要把Client中input和output名字分开
public interface StreamClient {
String INPUT = "message_input";
String OUTPUT="message_output";
@Input(StreamClient.INPUT)
SubscribableChannel input();
@Output(StreamClient.INPUT)
MessageChannel output();
}
在StreamReceiver 中
@Component
@EnableBinding(StreamClient.class)
public class StreamReceiver {
@StreamListener(StreamClient.INPUT)
@SendTo(StreamClient.OUTPUT)
public void proccessInput(Object message){
log.info("stream receiver:{}",message);
}
@StreamListener(StreamClient.OUTPUT)
public void proccessOutput(Object message){
log.info("stream receiver:{}",message);
}
}
这样就不会报上述错误,再次重启后又有一个错误
java.lang.IllegalArgumentException: An output channel cannot be specified for a method that does not return a value
at org.springframework.util.Assert.isTrue(Assert.java:118) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPostProcessor
D
e
f
a
u
l
t
S
t
r
e
a
m
L
i
s
t
e
n
e
r
S
e
t
u
p
M
e
t
h
o
d
O
r
c
h
e
s
t
r
a
t
o
r
.
r
e
g
i
s
t
e
r
H
a
n
d
l
e
r
M
e
t
h
o
d
O
n
L
i
s
t
e
n
e
d
C
h
a
n
n
e
l
(
S
t
r
e
a
m
L
i
s
t
e
n
e
r
A
n
n
o
t
a
t
i
o
n
B
e
a
n
P
o
s
t
P
r
o
c
e
s
s
o
r
.
j
a
v
a
:
479
)
[
s
p
r
i
n
g
−
c
l
o
u
d
−
s
t
r
e
a
m
−
2.1.2.
R
E
L
E
A
S
E
.
j
a
r
:
2.1.2.
R
E
L
E
A
S
E
]
a
t
o
r
g
.
s
p
r
i
n
g
f
r
a
m
e
w
o
r
k
.
c
l
o
u
d
.
s
t
r
e
a
m
.
b
i
n
d
i
n
g
.
S
t
r
e
a
m
L
i
s
t
e
n
e
r
A
n
n
o
t
a
t
i
o
n
B
e
a
n
P
o
s
t
P
r
o
c
e
s
s
o
r
DefaultStreamListenerSetupMethodOrchestrator.registerHandlerMethodOnListenedChannel(StreamListenerAnnotationBeanPostProcessor.java:479) ~[spring-cloud-stream-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPostProcessor
DefaultStreamListenerSetupMethodOrchestrator.registerHandlerMethodOnListenedChannel(StreamListenerAnnotationBeanPostProcessor.java:479) [spring−cloud−stream−2.1.2.RELEASE.jar:2.1.2.RELEASE]atorg.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPostProcessorDefaultStreamListenerSetupMethodOrchestrator.orchestrateStreamListenerSetupMethod(StreamListenerAnnotationBeanPostProcessor.java:423) ~[spring-cloud-stream-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPostProcessor.doPostProcess(StreamListenerAnnotationBeanPostProcessor.java:226) ~[spring-cloud-stream-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPostProcessor.lambda$postProcessAfterInitialization$0(StreamListenerAnnotationBeanPostProcessor.java:196) ~[spring-cloud-stream-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at java.lang.Iterable.forEach(Iterable.java:75) ~[na:1.8.0_181]
at org.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPostProcessor.injectAndPostProcessDependencies(StreamListenerAnnotationBeanPostProcessor.java:330) ~[spring-cloud-stream-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPostProcessor.afterSingletonsInstantiated(StreamListenerAnnotationBeanPostProcessor.java:113) ~[spring-cloud-stream-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:866) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
Input信道需要有返回值,StreamReceiver代码需要修改
@StreamListener(StreamClient.INPUT)
@SendTo(StreamClient.OUTPUT)
public Object proccessInput(Object message){
log.info("stream receiver:{}",message);
return message;
}