我正在尝试遵循这个简单的guide for Spring RabbitMQ messaging。
我在自动布线方面有两个问题:
1.无法自动连接。找不到'ConnectionFactory'类型的Bean
1.无法自动连接。找不到'RabbitTemplate'类型的Bean。
我找不到我遗漏的内容,因为教程指出:
Sping Boot 自动创建一个连接工厂和一个RabbitTemplate,减少了您必须编写的代码量。
下面是我的pom.xml,以防我在这里遗漏了什么:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>RabbitMQDemoApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>RabbitMQDemoApp</name>
<description>RabbitMQDemoApp</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
3条答案
按热度按时间bnlyeluc1#
看起来问题出在Sping Boot 的版本中。在版本
2.7.0
中,它不能自动创建beanConnectionFactory
和RabbitTemplate
....当我将Spring Boot降级到版本2.6.8
时,一切工作正常。否则,如果您希望使用Sping Boot 2.7.0,则需要自己创建这些Bean。
tjrkku2a2#
Sping Boot 创建了这些bean,这是IDEA的一个问题(如果你使用它的话)。
lg40wkob3#
问题出在IDE上,而不是Spring框架的版本。我可以确认这一点,因为我能够编译它,甚至运行它,即使IntelliJ抱怨错误。以下是Gradle构建文件的屏幕截图,其中显示了Sping Boot 和Java


的版本
这就是IntelliJ所说的
我创建了一个新的项目,并降级到2.6.11版本的 Boot ,但保持相同版本的Java和一切似乎与IntelliJ现在OK。
这是IDE特有的问题。