解决:No qualifying bean of type ‘org.springframework.boot.autoconfigure.http.HttpMessageConverters‘
解决:No qualifying bean of type 'org.springframework.boot.autoconfigure.http.HttpMessageConverters' available: expected at least 1 bean which qualifies as autowire candidate.
种一棵树最好的时间是10年前,其次就是现在,加油!
--by蜡笔小柯南
错误信息
在使用Open Feign远程调用时,出现如下错误:
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)}
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)}
意思是:
没有可用的“HttpMessageConverters”类型的合格bean:至少需要1个符合autowire候选条件的bean
解决方法
由于缺少"HttpMessageConverters"类型的bean,我们只需要提供一个"HttpMessageConverters"类型的bean即可
可以在当前代码的目录中,新建一个名为config
的包,主要用于放配置相关的类
在config
包下新建配置类,我这里命名为HttpConverterConfig
,根据自己的需要进行命名,在类中注册"HttpMessageConverters"类型的bean
@Configuration
public class HttpConverterConfig {
@Bean
public HttpMessageConverters httpMessageConverter(ObjectProvider<HttpMessageConverter<?>> converters) {
return new HttpMessageConverters(converters.orderedStream().collect(Collectors.toList()));
}
}
注意:
此类一定要可以被Spring扫描到,才能生效。建议放在与主启动类同级或它的子包下
配置完成后,重启项目即可解决
更多推荐
所有评论(0)