如何解决无法让 spring cloud openfeign 与 jersey 注释一起使用
我正在尝试制作一个简单的模板应用程序,它使用 feign 调用一些外部服务来检索 cat 事实。我在使用 Jersey 注释时遇到了一些麻烦,如果可能,我想使用 Jersey 而不是 Spring mvc。
这是我的客户:
@FeignClient(name = "catFact",url = "${feign.url.catFactURL}",configuration = CatFactFeignConfiguration.class)
public interface CatFactClient {
/**
* Retrieves facts from an external cat facts service
*
* @param amount the amount of facts to retrieve
* @return a list of cat facts
*/
@Path("/facts/random")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@GET
public List<CatFact> getCatFacts(@QueryParam("amount") int amount);
}
这是 feign 客户端的基本配置:
@Configuration
public class CatFactFeignConfiguration {
@Bean
public OkHttpClient client() {
return new OkHttpClient();
}
@Bean
public BasicErrorDecoder errorDecoder() {
return new BasicErrorDecoder();
}
}
客户端是这样调用的:
@Service
@RequiredArgsConstructor
public class CatFactService {
private final CatFactClient feignClient;
public List<CatFact> getCatFacts(int amount) {
return feignClient.getCatFacts(amount);
}
}
这是我收到的错误消息:
Caused by: java.lang.IllegalStateException: Method CatFactClient#getCatFacts(int) not annotated with HTTP method type (ex. GET,POST)
我很确定我以前见过球衣与假装搭配使用,但我不确定。有谁知道这是否可能?我已经研究过定义一个 Contract bean,但我得到的唯一合同选项是默认的,它不起作用。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。