ReactiveFeignClient 错误:类具有合约默认未使用的注释 [ReactiveFeignClient]

问题描述 投票:0回答:1

我正在构建一个微服务,它使用另一个微服务中定义的 Reactive Feign Client 来获取一些数据。我添加了 feign 客户端的配置,启用了响应式 feign 客户端,但是当我运行程序时,我得到:

“CurrencyServiceClient 类具有合约默认不使用的注释 [ReactiveFeignClient]”和“方法 getCurrencyDefinition 具有合约默认不使用的注释 GetMapping”。

我不确定我的微服务中没有正确配置什么。 下面是我的代码:

  1. 来自货币服务的 ReactiveFeignClient
@ReactiveFeignClient(
        configuration = CurrencyServiceInternalClientConfiguration.class,
        value = "currency-service",
        path = "/currency-service/internal"
)
public interface CurrencyServiceClient {

    @GetMapping(path = "/users/{userId}/balances/{currencyId}")
    Mono<CurrencyBalanceResponse> getUserBalance(@PathVariable("userId") String userId,
                                                 @PathVariable("currencyId") Long currencyId);

    @GetMapping(path = "/currencies")
    Mono<CurrenciesResponse> getCurrenciesDefinition(@RequestParam(value = "userId", required = false) Optional<String> userId); ```
  1. 在其他微服务中使用反应式假客户端的服务
@RequiredArgsConstructor
@Service
@Slf4j
public class CurrenciesService {

    private final CurrencyServiceClient currencyServiceClient;

    public CompletableFuture<CurrenciesResponse> getCurrencies() {
        List<Currency> currenciesList = new ArrayList<>();
        return currencyServiceClient.getCurrenciesDefinition(Optional.empty())
                .toFuture()
                .thenCompose(currenciesResponse -> {
                    currenciesResponse.getCurrencies().stream().forEach(currency -> {
                        Long currentTimestamp = Instant.now().getMillis();
                        if (currency.getResetTimestamp() <= currentTimestamp) {
                            currenciesList.add(Currency.builder().id(currency.getId())
                                    .name(currency.getName()).build());
                        }
                    });
                    return CompletableFuture.completedFuture(CurrenciesResponse.builder()
                            .status(ResponseStatus.SUCCESS)
                            .currencies(currenciesList)
                            .build());
                })
                .exceptionally(exception -> CurrenciesResponse.builder()
                        .status(ResponseStatus.ERROR)
                        .build());
    }
}
  1. 配置
@Configuration
@AutoConfigureAfter(ReactiveFeignAutoConfiguration.class)
@ConditionalOnProperty(prefix = "currency-service.client", name = "enabled", havingValue = "true",matchIfMissing = false)
@EnableReactiveFeignClients(clients = CurrencyServiceClient.class)
public class CurrencyClientAutoConfiguration {
}

  1. 其他属性
feign:
  hystrix:
    enabled: true
currency-service:
  client:
    enabled: true
eager-load:
    clients: currency-service
    enabled: true

有人可以帮忙吗?

java spring spring-webflux reactive
1个回答
0
投票

问题解决了吗?我升级到SpringCloud2023.0.3时也遇到同样的问题。


Caused by: java.lang.IllegalStateException: Method RemoteDataScopeService#getDescendantList(Long) not annotated with HTTP method type (ex. GET, POST)
Warnings:
- Class RemoteDataScopeService has annotations [FeignClient] that are not used by contract Default
- Method getDescendantList has an annotation RequestMapping that is not used by contract Default

© www.soinside.com 2019 - 2024. All rights reserved.