[Springboot] Gateway 커스텀 필터 적용 안될 때/Gateway 안먹을 때

Hannana·2024년 12월 25일
  • 변경 전
spring:
  application:
    name: apigateway-service
  cloud:
    gateway:
    	mvn:
          routes:
            - id: first-service #when the service comes in,
              uri: http://localhost:8081/ #192.168.45.104 #allocate it at this port
              predicates:
                - Path=/first-service/** #when first-service comes, allocate 8081 port
              filters:
                - CustomFilter

Problem

  • 문제 발생 -> 커스텀 필터가 적용이 안되는 문제 발생❌
{
    "timestamp": "2024-12-25T17:40:16.953+00:00",
    "path": "/first-service/check",
    "status": 404,
    "error": "Not Found",
    "requestId": "b7d751fb-1"
}

-8081 원래 서비스 호출하면 잘 호출 되는 것으로 봐서, gateway 쪽 문제로 판단.
-CustomFilter 코드 -> 문제X
-yml 쪽에 필터가 안 먹는 것으로 추측하고 구글링해보니 중간에 적용했던 mvn.routes 가 특정한 상황에만 적용될 수도 있다고한다.
-그래서 그냥 routes로 변경

Solution

  • 변경 후
spring:
  application:
    name: apigateway-service
  cloud:
    gateway:
        routes:
          - id: first-service #when the service comes in,
            uri: http://localhost:8081/ #192.168.45.104 #allocate it at this port
            predicates:
              - Path=/first-service/** #when first-service comes, allocate 8081 port
            filters:
              - CustomFilter

routes에 원하는 결과가 출력된다.

profile
(구) https://hansjour.tistory.com/ 이사옴. 성장하는 하루를 쌓아가는 블로그

0개의 댓글