Spring Cloud 流无法自动装配 Source.class

编程入门 行业动态 更新时间:2024-10-25 23:36:45
本文介绍了Spring Cloud 流无法自动装配 Source.class的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在从头开始学习 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

本文发布于:2023-11-25 02:35:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627981.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Cloud   Spring   class   Source

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!