我使用的是2.1.5.RELEASE和Greenwich.SR1版本,前面讲的bus刷新,可以通过post手动刷新配置,但是到这里,修改了git网关配置,就不行,代码如下:
pom.xml配置
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>api-gateway</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>api-gateway</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
本地配置
server:
port: 9000
spring:
application:
name: api-gateway
cloud:
config:
discovery:
enabled: true
service-id: config-server
profile: dev
eureka:
client:
service-url:
defaultZone: http://localhost:8762/eureka/
instance:
instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}:${spring.application.instance_id:${server.port}}
prefer-ip-address: true
启动类
@SpringBootApplication
@EnableZuulProxy
public class ApiGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ApiGatewayApplication.class, args);
}
/**
* 动态路由
* @return
*/
@ConfigurationProperties("zuul")
@RefreshScope
public ZuulProperties zuulProperties() {
return new ZuulProperties();
}
}
git的网关配置
zuul:
#全部服务忽略敏感头(全部服务都可以传递cookie)
sensitive-headers:
routes:
# /myProduct/product/list -> /product/product/list
aaaaaa:
path: /oneProduct/**
serviceId: product
sensitiveHeaders: #显示敏感头信息(cookie,配置空即可)
#简洁写法
# product: /myProduct/**
#排除某些路由
ignored-patterns:
- /**/product/listForOrder
#暴露配置,
#通过:http://localhost:9000/actuator/routes可以查看所有匹配的路由
#低版本:http://localhost:9000/applicatio/routes查看
management:
endpoints:
web:
exposure:
include: "*"
ribbon:
ReadTimeout: 5000
SocketTimeout: 5000
SpringCloud组件实现微服务,【已升级Finchley.Release】
了解课程