gateway & nacos & ribbon负载 server: port: 8200 spring: application: name: lc-gateway cloud: nacos: discovery: #注册中心地址 server-addr: 127.0.0.1:8848 namespace: mainconsole config: server-addr: 127.0.0.1:8848 # 配置中心-指定命名空间 namespace: mainconsole # 指定配置文件后缀 file-extension: yaml #配置组 group: DEFAULT_GROUP #配置dateId data-id: lc-gateway #获取配置超时时间 timeout: 5000 gateway: #设置超时时间默认 httpclient: connect-timeout: 1000 response-timeout: 5s routes: - id: order_route # 路由的唯一标识,路由到order uri: lb://service-provider-xmh # 需要转发的地址 lb: 使用nacos中的本地负载均衡策略 # uri: http://127.0.0.1:9091/hello2 # 断言规则 用于路由规则的匹配 predicates: - Path=/order/** @EnableDiscoveryClient @SpringBootApplication(scanBasePackages="cn",exclude={DataSourceAutoConfiguration.class}) //@ComponentScan public class ApplicationXmhTest { public static void main(String[] args) { SpringApplication.run(ApplicationXmhTest.class, args); } <dependencies> <dependency> <groupId>com.alibaba.nacos</groupId> <artifactId>nacos-client</artifactId> <version>1.4.0</version> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <version>2021.1</version> <exclusions> <exclusion> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpasyncclient</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-commons</artifactId> <version>3.1.3</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bootstrap</artifactId> <version>3.1.3</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-gateway</artifactId> <version>3.1.4</version> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> <version>2021.1</version> </dependency> <dependency> <groupId>org.yaml</groupId> <artifactId>snakeyaml</artifactId> <version>1.33</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>5.3.23</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.13.4</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-loadbalancer</artifactId> <version>3.1.4</version> </dependency> </dependencies> 需要负载的应用实例配置 server.port=9091 spring.application.name=service-provider-xmh spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 spring.cloud.nacos.discovery.namespace=mainconsole <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.7.4</version> <exclusions> <exclusion> <groupId>org.hibernate.validator</groupId> <artifactId>hibernate-validator</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <version>2021.1</version> <exclusions> <exclusion> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpasyncclient</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-commons</artifactId> <version>3.1.3</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bootstrap</artifactId> <version>3.1.3</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.13.4</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-loadbalancer</artifactId> <version>3.1.4</version> </dependency> </dependencies>
标签:spring,nacos,springframework,starter,org,gateway,cloud From: https://www.cnblogs.com/xingminghui111/p/16768366.html