如果是Spring Boot项目,会自动为你配置ConnectionFactory和RabbitTemplate,使用时直接@Autowired RabbitTemplate rabbitTemplate 即可得到RabbitTemplate对象。 2.如果使用的是普通Spring项目,则需要手动配置ConnectionFactory和RabbitTemplate。