我有调用TMDB api的应用程序。对于api调用,我使用Feign接口:
@FeignClient(name = "TMDb-movie", url = "${TMDB_URL}", path = "/movie")
public interface TmdbMovieRMI {
@GetMapping(value = "/{id}", consumes = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<String> findById(@PathVariable Integer id,
@RequestParam("api_key") String apiKey);
}但是当我执行请求时,我遇到了这个错误:feign.codec.DecodeException: No qualifying bean of type 'org.springframework.boot.autoconfigure.http.HttpMessageConverters' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}如何修复它?
发布于 2020-07-01 19:59:01
如果您没有使用webmvc (例如,因为您使用的是webflux或根本没有web spring启动程序),feign客户端将无法开箱即用。
您必须手动定义编码器和解码器。将此代码插入到@Configuration类或@SpringBootApplication类中:
@Bean
public Decoder decoder(ObjectMapper objectMapper) {
return new JacksonDecoder(objectMapper);
}
@Bean
public Encoder encoder(ObjectMapper objectMapper) {
return new JacksonEncoder(objectMapper);
}也许您的pom.xml中也需要这个额外的依赖项
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-jackson</artifactId>
</dependency>https://stackoverflow.com/questions/61988527
复制相似问题