Spring Cloud Alibaba Nacos+Gateway503錯誤,No servers available for service
阿新 • • 發佈:2022-05-17
問題如下:
1.LoadBalancerCacheManager不可用,添加了下面的依賴還是不管用
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-loadbalancer</artifactId> </dependency>
2.No servers available for service 找不到服務
閘道器application.yml配置如下
server: port: 88 spring: application: name: gulimall-gateway cloud: nacos: discovery: server-addr: 127.0.0.1:8848 gateway: routes: - id: admin_route #uri: lb://renren-fast uri: http://localhost:8080 predicates: - Path=/api/** filters: - RewritePath=/api/(?<segment>.*), /renren-fast/$\{segment}
uri: lb//demo-server 就會出現這個問題,但是 uri: http://localhost:8080卻不會No servers available for service
由於springcloud2020棄用了Ribbon,因此Alibaba在2021版本nacos中刪除了Ribbon的jar包,因此無法通過lb路由到指定微服務,出現了503情況。
另外還有可能出現這個錯誤:在classpath上發現的Spring MVC,與Spring Cloud Gateway不相容
原因是因為spring cloud gateway 是建立在spring boot 2.x 和 spring webflux基礎上的既:gateway 本身已經包含了spring mvc 的功能,正與提示的一樣和spring boot 的web starter衝突了
解決方法:排除common中的spring-webmvc依賴
<dependency> <groupId>com.atguigu.gulimall</groupId> <artifactId>gulimall-common</artifactId> <version>0.0.1-SNAPSHOT</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </exclusion> </exclusions> </dependency>