spring-cloud-gateway+nacos实现动态配置

pom.xml


    org.springframework.boot
    spring-boot-starter-parent
    2.3.7.RELEASE
  

  
    
      
        org.springframework.cloud
        spring-cloud-dependencies
        Hoxton.RELEASE
        pom
        import
      

      
        com.alibaba.cloud
        spring-cloud-alibaba-dependencies
        2.2.7.RELEASE
        pom
        import
      
    
  

  

    
      org.springframework.cloud
      spring-cloud-starter-gateway
    

    
      org.springframework.boot
      spring-boot-starter-validation
    

    
      com.alibaba.cloud
      spring-cloud-starter-alibaba-nacos-discovery
    

    
      com.alibaba.cloud
      spring-cloud-starter-alibaba-nacos-config
    

    
        org.projectlombok
        lombok
    

  

bootstrap.xml

server:
  port: 9100

spring:
  application:
    name: scgateway-demo
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848
        namespace: b2b3c55a-abe5-47a4-a47e-03c57138d1d7
      config:
        file-extension: yml
        prefix: ${spring.application.name}
        server-addr: 127.0.0.1:8848
        namespace: b2b3c55a-abe5-47a4-a47e-03c57138d1d7
        group: DEFAULT_GROUP

启动类:

@EnableDiscoveryClient
@SpringBootApplication
public class SCGatewayApp {

    public static void main(String[] args) {
        SpringApplication.run(SCGatewayApp.class, args);
    }

}

nacos端配置:

spring-cloud-gateway+nacos实现动态配置_第1张图片

 spring-cloud-gateway+nacos实现动态配置_第2张图片

spring-cloud-gateway+nacos实现动态配置_第3张图片

spring:
  cloud:
    gateway:
      routes:
        - id: nacos
          uri: lb://nacos-payment-provider
          predicates:
            - Path=/payment-service/**
          filters:
            - StripPrefix=1

源码:GitHub - hunqi/scgateway-demo: spring cloud gateway demo

集成sentinel: Sentinel/sentinel-demo/sentinel-demo-spring-cloud-gateway at master · alibaba/Sentinel · GitHub

你可能感兴趣的:(springcloud,gateway,nacos,动态路由配置)