• 记一次gateway微服务启动报错


     这个gateway微服务之前启动没题,改了一下父依赖就启动不了了。

    之前的父依赖是springboot-parent,后来我想把这个微服务改在我项目的父依赖下,就改了一下父依赖。

    1. <parent>
    2. <artifactId>ac-mall-cloudartifactId>
    3. <groupId>org.examplegroupId>
    4. <version>1.0-SNAPSHOTversion>
    5. parent>

    改完就报错了。 

    错误信息如下:

    1. Description:
    2. Parameter 0 of method redisRateLimiter in org.springframework.cloud.gateway.config.GatewayRedisAutoConfiguration required a single bean, but 2 were found:
    3. - reactiveStringRedisTemplate: defined by method 'reactiveStringRedisTemplate' in class path resource [org/springframework/boot/autoconfigure/data/redis/RedisReactiveAutoConfiguration.class]
    4. - stringReactiveRedisTemplate: defined by method 'stringReactiveRedisTemplate' in class path resource [org/springframework/cloud/gateway/config/GatewayRedisAutoConfiguration.class]
    5. Action:
    6. Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

    大致意思就是在org.springframework.cloud.gateway.config.GatewayRedisAutoConfiguration这个配置类中有两个redisRateLimiter的实例,冲突了。然后我看了下引入的依赖的pom文件,又看了下其他子服务的pom文件,发现gateway微服务里的依赖和父服务里引入的依赖冲突了,多引了依赖。

    下面是gateway微服务中的依赖:

    1. "1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    5. <parent>
    6. <artifactId>ac-mall-cloudartifactId>
    7. <groupId>org.examplegroupId>
    8. <version>1.0-SNAPSHOTversion>
    9. parent>
    10. <modelVersion>4.0.0modelVersion>
    11. <groupId>org.acgroupId>
    12. <artifactId>gateway-serviceartifactId>
    13. <properties>
    14. <spring-cloud.version>Greenwich.SR3spring-cloud.version>
    15. <alibaba.cloud.version>2.1.0.RELEASEalibaba.cloud.version>
    16. properties>
    17. <dependencyManagement>
    18. <dependencies>
    19. <dependency>
    20. <groupId>org.springframework.cloudgroupId>
    21. <artifactId>spring-cloud-dependenciesartifactId>
    22. <version>${spring-cloud.version}version>
    23. <type>pomtype>
    24. <scope>importscope>
    25. dependency>
    26. <dependency>
    27. <groupId>com.alibaba.cloudgroupId>
    28. <artifactId>spring-cloud-alibaba-dependenciesartifactId>
    29. <version>${alibaba.cloud.version}version>
    30. <type>pomtype>
    31. <scope>importscope>
    32. dependency>
    33. dependencies>
    34. dependencyManagement>
    35. ......
    36. project>

     下面是父依赖中的pom文件:

    1. "1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    5. <modelVersion>4.0.0modelVersion>
    6. <groupId>org.examplegroupId>
    7. <artifactId>ac-mall-cloudartifactId>
    8. <version>1.0-SNAPSHOTversion>
    9. ......
    10. <packaging>pompackaging>
    11. <properties>
    12. <java.version>1.8java.version>
    13. <spring-cloud.version>Hoxton.SR8spring-cloud.version>
    14. <alibaba.cloud.version>2.2.5.RELEASEalibaba.cloud.version>
    15. properties>
    16. <dependencyManagement>
    17. <dependencies>
    18. <dependency>
    19. <groupId>org.springframework.bootgroupId>
    20. <artifactId>spring-boot-starter-parentartifactId>
    21. <version>${boot.version}version>
    22. <type>pomtype>
    23. <scope>importscope>
    24. dependency>
    25. <dependency>
    26. <groupId>org.springframework.cloudgroupId>
    27. <artifactId>spring-cloud-dependenciesartifactId>
    28. <version>${spring-cloud.version}version>
    29. <type>pomtype>
    30. <scope>importscope>
    31. dependency>
    32. <dependency>
    33. <groupId>com.alibaba.cloudgroupId>
    34. <artifactId>spring-cloud-alibaba-dependenciesartifactId>
    35. <version>${alibaba.cloud.version}version>
    36. <type>pomtype>
    37. <scope>importscope>
    38. dependency>
    39. ......
    40. dependencies>
    41. dependencyManagement>
    42. ......
    43. project>

     从这两个pom文件可以看到,在父依赖中已经引入了springcloud依赖和alibabacloud依赖,而且版本和gateway中的版本也不一样,把gateway微服务pom文件改成下面这种就可以启动了。

    把所有父依赖pom中已经引入过的依赖注释掉就可以了。

    1. "1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    5. <parent>
    6. <artifactId>ac-mall-cloudartifactId>
    7. <groupId>org.examplegroupId>
    8. <version>1.0-SNAPSHOTversion>
    9. parent>
    10. <modelVersion>4.0.0modelVersion>
    11. <groupId>org.acgroupId>
    12. <artifactId>gateway-serviceartifactId>
    13. ......
    14. project>

  • 相关阅读:
    iOS支付时出现Unknow错误的问题
    微信公众号根据关键词取文章列表 API
    Kafka Stream 学习笔记-4 window and state store
    Oracle 注释详解(--、/**/、rem)
    Redis数据类型
    初识设计模式 - 模板方法模式
    关于STM32时钟系统的理解
    java 企业工程管理系统软件源码 自主研发 工程行业适用
    Gson简介
    3D游戏角色动画
  • 原文地址:https://blog.csdn.net/weixin_44259233/article/details/127666206