Spring Cloud API Gateway-spring.cloud.gateway.discovery.locator.lower-case-service-id=true不支持URL-未找到404

y53ybaqx  于 2022-10-23  发布在  Spring
关注(0)|答案(2)|浏览(173)

我在将一些URL从API网关调用到一个微服务时遇到了问题。下面显示的两个URL不起作用,并抛出404未找到错误。

http://localhost:8765/currency-conversion/currency-conversion/from/USD/to/INR/quantity/10
http://localhost:8765/currency-conversion/currency-conversion-feign/from/USD/to/INR/quantity/10

这里是API网关应用属性文件

spring.application.name=api-gateway
server.port=8765
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
eureka.instance.hostname=localhost

# http://localhost:8765/CURRENCY-CONVERSION/currency-conversion/from/USD/to/INR/quantity/10 (Working)

# http://localhost:8765/CURRENCY-CONVERSION/currency-conversion-feign/from/USD/to/INR/quantity/10 (Working)

spring.cloud.gateway.discovery.locator.enabled=true

# http://localhost:8765/currency-conversion/currency-conversion/from/USD/to/INR/quantity/10 (Not Working)

# http://localhost:8765/currency-conversion/currency-conversion-feign/from/USD/to/INR/quantity/10 (Not Working)

spring.cloud.gateway.discovery.locator.lower-case-service-id=true

以下是货币转换-服务应用程序属性文件

spring.config.import=optional:configserver:http://localhost:8888
spring.application.name=currency-conversion
server.port=8100

eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
eureka.instance.hostname=localhost

以下是货币兑换服务控制器

@RestController
public class CurrencyConversionController {

    @GetMapping("/currency-conversion/from/{from}/to/{to}/quantity/{quantity}")
    public CurrencyConversion calculateCurrencyConversion(
            @PathVariable String from,
            @PathVariable String to,
            @PathVariable BigDecimal quantity
    ) {
    }

    @GetMapping("/currency-conversion-feign/from/{from}/to/{to}/quantity/{quantity}")
    public CurrencyConversion calculateCurrencyConversionFeign(
            @PathVariable String from,
            @PathVariable String to,
            @PathVariable BigDecimal quantity
    ) {
    }

}

我怎么才能修好它?

jljoyd4f

jljoyd4f1#

我更改了微服务的名称,如下所示,它起作用了
从…
Spring.applation.name=货币兑换

Spring.applation.name=货币兑换-毫秒
从…
Spring.Applation.name=货币兑换

Spring.application.name=currency-conversion-ms

aelbi1ox

aelbi1ox2#

我认为你应该拥有如下财产:

spring.cloud.gateway.discovery.locator.lowerCaseServiceId=true

所以没有破折号,只有 Camel 的箱子。

相关问题