【发布时间】:2019-06-06 15:16:37
【问题描述】:
由于 Spring Cloud Stream 没有用于将新消息发送到流的注释(@SendTo 仅在声明 @StreamListener 时有效),因此我尝试为此使用 Spring Integration 注释,即 @Publisher。
由于Spring Cloud Stream的@Publisher带一个通道,而Spring Cloud Stream的@EnableBinding注解可以使用@Output注解绑定一个输出通道,所以我尝试通过以下方式混合它们:
@EnableBinding(MessageSource.class)
@Service
public class ExampleService {
@Publisher(channel = MessageSource.OUTPUT)
public String sendMessage(String message){
return message;
}
}
另外,我在配置文件中声明了@EnablePublisher 注解:
@SpringBootApplication
@EnablePublisher("")
public class ExampleApplication {
public static void main(String[] args){
SpringApplication.run(ExampleApplication.class, args);
}
}
我的测试:
@RunWith(SpringRunner.class)
@SpringBootTest
public class ExampleServiceTest {
@Autowired
private ExampleService exampleService;
@Test
public void testQueue(){
exampleService.queue("Hi!");
System.out.println("Ready!");
}
}
但我收到以下错误:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.example.ExampleServiceTest': Unsatisfied dependency expressed through field 'exampleService'; nested exception is
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'exampleService' is expected to be of type 'com.example.ExampleService' but was actually of type 'com.sun.proxy.$Proxy86'
这里的问题是无法注入ExampleService bean。
有谁知道我怎样才能完成这项工作?
谢谢!
【问题讨论】:
标签: spring spring-boot spring-integration spring-cloud spring-cloud-stream