pom
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
只有网关依赖
Spring Boot 版本是 2.1.0.RELEASE,
Spring Clound 版本是Finchley.RELEASE
application.yml
server:
port: 7001
spring:
application:
name: api-geteway
cloud:
gateway:
routes:
- id: 163
uri: http://www.163.com/
predicates:
- Path=/163/**
网关转发路径 写死 测试使用
项目启动 异常
2018-11-13 18:12:00.738 WARN 13744 --- [ main] onfigReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webHandler' defined in class path resource [org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration$EnableWebFluxConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'routePredicateHandlerMapping' defined in class path resource [org/springframework/cloud/gateway/config/GatewayAutoConfiguration.class]: Unsatisfied dependency expressed through method 'routePredicateHandlerMapping' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'filteringWebHandler' defined in class path resource [org/springframework/cloud/gateway/config/GatewayAutoConfiguration.class]: Unsatisfied dependency expressed through method 'filteringWebHandler' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'websocketRoutingFilter' defined in class path resource [org/springframework/cloud/gateway/config/GatewayAutoConfiguration.class]: Unsatisfied dependency expressed through method 'websocketRoutingFilter' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.web.reactive.socket.client.WebSocketClient' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2018-11-13 18:12:00.758 INFO 13744 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-11-13 18:12:00.911 ERROR 13744 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method websocketRoutingFilter in org.springframework.cloud.gateway.config.GatewayAutoConfiguration required a bean of type 'org.springframework.web.reactive.socket.client.WebSocketClient' that could not be found.
The following candidates were found but could not be injected:
- Bean method 'reactorNettyWebSocketClient' in 'GatewayAutoConfiguration.NettyConfiguration' not loaded because @ConditionalOnClass did not find required class 'reactor.ipc.netty.http.client.HttpClient'
Action:
Consider revisiting the entries above or defining a bean of type 'org.springframework.web.reactive.socket.client.WebSocketClient' in your configuration.
Disconnected from the target VM, address: '127.0.0.1:52208', transport: 'socket'
Process finished with exit code 1
why?
解决方案:
我使用的Spring Boot 版本是 2.1.0.RELEASE, 使用的Spring Clound 版本是Finchley.RELEASE ,
后找到原因 Spring Clound 版本 Finchley.RELEASE 不兼容 Spring Boot 2.1.0.RELEASE 汗,
Spring Boot 版本改为 2.0.0.RELEASE 网关使用ok