Spring Cloud API Gateway Route for application.yml file

Viewed 33

I have a problem about converting configuration file to application.properties.yml file with respect to route path.

I already defined a bean for defining routes for my spring microservices example.

I just want to do that in application.properties.yml.

I wrote some snippets regarding it in application.properties.yml but it didn't work.

Where is the problem? How can I fix it?

Here is the configuration part of api gateway shown below

@Configuration
public class ApiGatewayConfiguration {
    
    @Bean
    public RouteLocator gatewayRouter(RouteLocatorBuilder builder) {
        return builder.routes()
                .route(p -> p
                        .path("/get")
                        .filters(f -> f
                                .addRequestHeader("MyHeader", "MyURI")
                                .addRequestParameter("Param", "MyValue"))
                        .uri("http://httpbin.org:80"))
                .route(p -> p.path("/currency-exchange/**")
                        .uri("lb://currency-exchange"))
                .route(p -> p.path("/currency-conversion/**")
                        .uri("lb://currency-conversion"))
                .route(p -> p.path("/currency-conversion-feign/**")
                        .uri("lb://currency-conversion"))
                .route(p -> p.path("/currency-conversion-new/**")
                        .filters(f -> f.rewritePath(
                                "/currency-conversion-new/(?<segment>.*)", 
                                "/currency-conversion-feign/${segment}"))
                        .uri("lb://currency-conversion"))
                .build();
    }

}

Here is the application.properties.yml shown below

spring:
   application:
      name: api-gateway
   cloud:
      gateway:
      discovery:
         locator:
            enabled: true
            lower-case-service-id=true
      routes:
         - id: currency-exchange
            uri: lb://currency-exchange
            predicates:
            - Path=/currency-exchange/**"
         - id: currency-conversion
            uri: lb://currency-conversion
            predicates:
            - Path=/currency-conversion/**
         - id: currency-conversion-feign
            uri: lb://currency-conversion
            predicates:
            - Path=/currency-conversion-feign/**
         - id: currency-conversion-custom-path
            uri: lb://currency-conversion
            predicates:
            - Path=/currency-conversion-new/**
            filters:
            - RewritePath=/currency-conversion-new/(?<segment>.*)", /currency-conversion-feign/${segment}
 
server:
   port: ${app_port}
eureka:
   client:
      serviceURL:
         defaultZone: http://localhost:8761/eureka
0 Answers
Related