我正在从头开始学习 Spring Cloud Streams.
I am learning Spring Cloud Streams from scratch.
我尝试创建这样的 Source 应用程序:
I tried to create a Source application like this:
import org.springframework.cloud.stream.messaging.Source; //etc @RestController @SpringBootApplication @CrossOrigin @EnableBinding(Source.class) public class StreamsProducerApplication { @Autowired Source source; @GetMapping(value="/send/{message}") public void sendMessage(@PathVariable String message){ if(message != null){ source.output().send(MessageBuilder.withPayload(message).build());} } public static void main(String[] args) { SpringApplication.run(StreamsProducerApplication.class, args); }}
但是,我从 Intellij IDEA 的Source source"得到错误提示;说无法自动装配.未找到‘源’类型的 bean.
However, I get error hint from Intellij IDEA at "Source source;" saying "Could not autowire. No beans of 'Source' type found.
我可以理解Source是我从中导入的接口,但是spring官网说Spring Cloud Stream为您创建了该接口的实现.您可以通过自动装配在应用程序中使用它"docs.spring.io/spring-cloud-stream/docs/current/reference/htmlsingle/
I can understand that Source is a interface from where I import, but the spring official website says "Spring Cloud Stream creates an implementation of the interface for you. You can use this in the application by autowiring it" docs.spring.io/spring-cloud-stream/docs/current/reference/htmlsingle/
那我是怎么做错的呢?谢谢.
So how did I do this wrong? Thank you.
推荐答案只是 Intellij IDEA 不知道 @EnableBinding(Source.class) 将在运行时成为一个 bean.只有这样的 bean 定义,所以工具无法确定在 @Autowired 中注入什么.
It is just the Intellij IDEA doesn't know that @EnableBinding(Source.class) is going to be a bean at runtime. There is just on such a bean definition, so tooling fails to determine what to inject in that @Autowired.
否则,您的代码完全没有问题,您只需要运行它并使用您对该代码的期望即可.
Otherwise your code is fully good and you just need to run it and play with whatever you expect from that code.
更多推荐
Spring Cloud 流无法自动装配 Source.class
发布评论