我在微服务应用程序中使用spring嵌入式Zuul代理和eureka服务注册表。 将Spring Cloud依赖项升级到格林威治后,它在zuul网关级别给出404错误。
以下是我的配置。
Zuul网关主类
@SpringBootApplication
@EnableZuulProxy
@EnableSwagger2
@EnableHystrixDashboard
@EnableHystrix
public class GatewayApplication {
}
application.yml
zuul:
ignoreSecurityHeaders: false
sensitiveHeaders:
routes:
oauth:
path: /oauth/**
serviceId: oauth-server
payment:
path: /payment/**
serviceId: payment-service
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8082/eureka/
registerWithEureka: true
spring:
application:
name: zuul-gateway
付款服务主类
@SpringBootApplication()
@EnableJpaRepositories({ "com.payment.repo" })
@EntityScan("com.payment.domain")
@EnableEurekaClient
@EnableSwagger2
public class PaymentServiceApplication {}
application.yml
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8082/eureka/
registerWithEureka: true
spring:
application:
name: payment-service
我能够使用Finchley.RELEASE将请求成功转发到zuul代理的服务。以下是以前的Maven依赖项。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.zipkin.brave</groupId>
<artifactId>brave-bom</artifactId>
<version>5.4.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
在将Spring Cloud依赖项升级到Greenwich.release之后,我无法将请求转发到来自zuul代理的服务。给出404。
因为以前在zuul中致电付款服务时,URL显示为
http://localhost:8181/payment/v1/fundTransfer/test
现在它显示为
http://localhost:8181/v1/fundTransfer/test
看来zuul没有添加路径值(付款)。如果我恢复使用Finchley,则在相同的配置下也可以正常工作。
我是否需要在zuul代理的application.yml中更改任何路由配置?