这个gateway微服务之前启动没题,改了一下父依赖就启动不了了。
之前的父依赖是springboot-parent,后来我想把这个微服务改在我项目的父依赖下,就改了一下父依赖。
- <parent>
-
- <artifactId>ac-mall-cloudartifactId>
- <groupId>org.examplegroupId>
- <version>1.0-SNAPSHOTversion>
- parent>
改完就报错了。
错误信息如下:
- Description:
-
- Parameter 0 of method redisRateLimiter in org.springframework.cloud.gateway.config.GatewayRedisAutoConfiguration required a single bean, but 2 were found:
- - reactiveStringRedisTemplate: defined by method 'reactiveStringRedisTemplate' in class path resource [org/springframework/boot/autoconfigure/data/redis/RedisReactiveAutoConfiguration.class]
- - stringReactiveRedisTemplate: defined by method 'stringReactiveRedisTemplate' in class path resource [org/springframework/cloud/gateway/config/GatewayRedisAutoConfiguration.class]
-
-
- Action:
-
- 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.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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
-
- <artifactId>ac-mall-cloudartifactId>
- <groupId>org.examplegroupId>
- <version>1.0-SNAPSHOTversion>
- parent>
- <modelVersion>4.0.0modelVersion>
-
- <groupId>org.acgroupId>
- <artifactId>gateway-serviceartifactId>
-
- <properties>
- <spring-cloud.version>Greenwich.SR3spring-cloud.version>
- <alibaba.cloud.version>2.1.0.RELEASEalibaba.cloud.version>
- properties>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.springframework.cloudgroupId>
- <artifactId>spring-cloud-dependenciesartifactId>
- <version>${spring-cloud.version}version>
- <type>pomtype>
- <scope>importscope>
- dependency>
-
- <dependency>
- <groupId>com.alibaba.cloudgroupId>
- <artifactId>spring-cloud-alibaba-dependenciesartifactId>
- <version>${alibaba.cloud.version}version>
- <type>pomtype>
- <scope>importscope>
- dependency>
- dependencies>
- dependencyManagement>
-
- ......
-
- project>
下面是父依赖中的pom文件:
- "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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0modelVersion>
-
- <groupId>org.examplegroupId>
- <artifactId>ac-mall-cloudartifactId>
- <version>1.0-SNAPSHOTversion>
-
- ......
-
- <packaging>pompackaging>
-
- <properties>
- <java.version>1.8java.version>
- <spring-cloud.version>Hoxton.SR8spring-cloud.version>
- <alibaba.cloud.version>2.2.5.RELEASEalibaba.cloud.version>
- properties>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-parentartifactId>
- <version>${boot.version}version>
- <type>pomtype>
- <scope>importscope>
- dependency>
-
- <dependency>
- <groupId>org.springframework.cloudgroupId>
- <artifactId>spring-cloud-dependenciesartifactId>
- <version>${spring-cloud.version}version>
- <type>pomtype>
- <scope>importscope>
- dependency>
-
- <dependency>
- <groupId>com.alibaba.cloudgroupId>
- <artifactId>spring-cloud-alibaba-dependenciesartifactId>
- <version>${alibaba.cloud.version}version>
- <type>pomtype>
- <scope>importscope>
- dependency>
-
- ......
-
- dependencies>
- dependencyManagement>
- ......
- project>
从这两个pom文件可以看到,在父依赖中已经引入了springcloud依赖和alibabacloud依赖,而且版本和gateway中的版本也不一样,把gateway微服务pom文件改成下面这种就可以启动了。
把所有父依赖pom中已经引入过的依赖注释掉就可以了。
- "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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
-
- <artifactId>ac-mall-cloudartifactId>
- <groupId>org.examplegroupId>
- <version>1.0-SNAPSHOTversion>
- parent>
- <modelVersion>4.0.0modelVersion>
-
- <groupId>org.acgroupId>
- <artifactId>gateway-serviceartifactId>
-
-
-
-
-
- ......
-
- project>