SpringCloud 서비스 게 이 트 웨 이 경로 규칙 의 구덩이 및 해결
4017 단어 SpringCloud게 이 트 웨 이경로
필 자 는 최근 에 SpringCloud 서비스 게 이 트 웨 이 를 사용 할 때 서비스 게 이 트 웨 이 경로 테스트 를 실시 한 결과 자신 이 설정 한 규칙 에 따라 테스트 할 수 없 음 을 발견 했다.테스트 할 때 다음 과 같다.
잘못된 조 사 를 통 해 알 고 보 니 경로 규칙 이 잘못 썼 구나!
경로 규칙 은 다음 과 같 습 니 다(오류)
#
server:
port: 8080
spring:
# , wc-gateway
application:
name: wc-gateway
profiles:
active: dev
#
zuul:
host:
connect-timeout-millis: 60000
socket-timeout-millis: 60000
#
routes:
api:
path: /api/user/**
serviceId: wc-client-user
해결 방안routes 및 이하 속성 을 왼쪽으로 이동 하여 host 와 같은 단계 로 이동 하면 됩 니 다.
수 정 된 경로 규칙
#
server:
port: 8080
spring:
# , wc-gateway
application:
name: wc-gateway
profiles:
active: dev
#
zuul:
host:
connect-timeout-millis: 60000
socket-timeout-millis: 60000
#
routes:
api:
path: /api/user/**
serviceId: wc-client-user
자,문제 가 해결 되 었 습 니 다.우 리 는 응용 테스트 를 다시 시작 합 니 다.테스트 결 과 는 예상 과 같 습 니 다.SpringCloud 진급 의 Zuul(경로 게 이 트 웨 이)
1.Zuul(경로 게 이 트 웨 이)
Zuul 은 요청 한 경로 와 여과 두 가지 가장 주요 한 기능 을 포함 합 니 다.
경로 기능:외부 요 구 를 구체 적 인 마이크로 서비스 사례 에 전달 하 는 것 은 외부 방문 통일 입 구 를 실현 하 는 기초 이다.
여과 기능:요청 한 처리 과정 에 관여 하 는 것 은 검사 요청,서비스 취 합 등 기능 을 실현 하 는 기초 입 니 다.
Zuul 서 비 스 는 결국 Eureka 에 등록 합 니 다.
1.1 루트 기본 설정
새 마이크로 서비스 클 라 우 드-zul-gateway-9527
// pom.xml
<!-- zuul -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
// application.yml
server:
port: 9527
spring:
application:
name: microservicecloud-zuul-gateway
eureka:
client:
service-url:
defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
instance:
instance-id: gateway-9527.com
prefer-ip-address: true
info:
app.name: noodles-microcloud
company.name: www.google.com
build.artifactId: $project.artifactId$
build.version: $project.version$
// hosts : 127.0.0.1 myzuul.com
//
@SpringBootApplication
@EnableZuulProxy
public class Zuul_9527_StartSpringCloudApp {
public static void main(String[] args) {
SpringApplication.run(Zuul_9527_StartSpringCloudApp.class, args);
}
}
//
// Eureka
// microservicecloud-provider-dept-8001
//
// :
// : http://localhost:8001/dept/get/1
// : http://myzuul.com:9527/microservicecloud-dept/dept/get/1
1.2 Zuul 경로 접근 맵 규칙
// microservicecloud-zuul-gateway-9527
// application.yml
zuul:
ignored-services: microservicecloud-dept #
routes:
prefix: /test # , :http://myzuul.com:9527/test/mydept/dept/get/1
mydept.serviceId: microservicecloud-dept
mydept.path: /mydept/**
// , : http://myzuul.com:9527/microservicecloud-dept/dept/get/1
// , : http://myzuul.com:9527/mydept/dept/get/1
이상 은 개인 적 인 경험 이 므 로 여러분 에 게 참고 가 되 기 를 바 랍 니 다.여러분 들 도 저 희 를 많이 응원 해 주시 기 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[Spring Cloud] LoadBancer-01discoveryservice-eureka 라는 프로젝트를 생성한다 3개 항목을 추가한다. 1. DiscoveryserviceEurekaApplication.java 생성된 -application에 @EnableEu...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.