Spring无法自动连接RabbitMQ的ConnectionFactory

hmtdttj4  于 2022-11-08  发布在  RabbitMQ
关注(0)|答案(3)|浏览(630)

我正在尝试遵循这个简单的guide for Spring RabbitMQ messaging
我在自动布线方面有两个问题:
1.无法自动连接。找不到'ConnectionFactory'类型的Bean
1.无法自动连接。找不到'RabbitTemplate'类型的Bean。
我找不到我遗漏的内容,因为教程指出:
Sping Boot 自动创建一个连接工厂和一个RabbitTemplate,减少了您必须编写的代码量。
下面是我的pom.xml,以防我在这里遗漏了什么:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.7.0</version>
  9. <relativePath/> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>com.example</groupId>
  12. <artifactId>RabbitMQDemoApp</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>RabbitMQDemoApp</name>
  15. <description>RabbitMQDemoApp</description>
  16. <properties>
  17. <java.version>11</java.version>
  18. </properties>
  19. <dependencies>
  20. <dependency>
  21. <groupId>org.springframework.boot</groupId>
  22. <artifactId>spring-boot-starter-amqp</artifactId>
  23. </dependency>
  24. <dependency>
  25. <groupId>org.springframework.boot</groupId>
  26. <artifactId>spring-boot-devtools</artifactId>
  27. <scope>runtime</scope>
  28. <optional>true</optional>
  29. </dependency>
  30. <dependency>
  31. <groupId>org.springframework.boot</groupId>
  32. <artifactId>spring-boot-starter-test</artifactId>
  33. <scope>test</scope>
  34. </dependency>
  35. <dependency>
  36. <groupId>org.springframework.amqp</groupId>
  37. <artifactId>spring-rabbit-test</artifactId>
  38. <scope>test</scope>
  39. </dependency>
  40. </dependencies>
  41. <build>
  42. <plugins>
  43. <plugin>
  44. <groupId>org.springframework.boot</groupId>
  45. <artifactId>spring-boot-maven-plugin</artifactId>
  46. </plugin>
  47. </plugins>
  48. </build>
  49. </project>
bnlyeluc

bnlyeluc1#

看起来问题出在Sping Boot 的版本中。在版本2.7.0中,它不能自动创建bean ConnectionFactoryRabbitTemplate ....当我将Spring Boot降级到版本2.6.8时,一切工作正常。
否则,如果您希望使用Sping Boot 2.7.0,则需要自己创建这些Bean。

tjrkku2a

tjrkku2a2#

Sping Boot 创建了这些bean,这是IDEA的一个问题(如果你使用它的话)。

lg40wkob

lg40wkob3#

问题出在IDE上,而不是Spring框架的版本。我可以确认这一点,因为我能够编译它,甚至运行它,即使IntelliJ抱怨错误。以下是Gradle构建文件的屏幕截图,其中显示了Sping Boot 和Java

的版本
这就是IntelliJ所说的

我创建了一个新的项目,并降级到2.6.11版本的 Boot ,但保持相同版本的Java和一切似乎与IntelliJ现在OK。

这是IDE特有的问题。

相关问题