gpt4 book ai didi

spring-cloud - 是否可以在 BootstrapConfiguration 上使用 @EnableFeignClients?

转载 作者:行者123 更新时间:2023-12-05 01:01:12 24 4
gpt4 key购买 nike

我想使用来自 PropertySourceLocator 的伪装客户端必须在引导期间注册。我的 spring.factories 中有以下内容:

org.springframework.cloud.bootstrap.BootstrapConfiguration=\
test.PropertiesConfiguration


@Configuration
@EnableFeignClients
public class PropertiesConfiguration {

@Bean
public PropertySourceLocator propertySourceLocator() {
return new MyPropertySourceLocator();
}
}

伪装客户端自动连接到 MyPropertySourceLocator .然而,虽然同一个客户端在普通 bean 中工作,但它在这里不起作用。所有请求都失败并出现此异常:
feign.codec.DecodeException: No qualifying bean of type [org.springframework.boot.autoconfigure.web.HttpMessageConverters] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at feign.SynchronousMethodHandler.decode(SynchronousMethodHandler.java:173)
at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:141)
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:96)
at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:92)
at com.sun.proxy.$Proxy23.get(Unknown Source)
at test.MyPropertySourceLocator$1.getProperty(MyPropertySourceLocator.java:32)
at org.springframework.core.env.CompositePropertySource.getProperty(CompositePropertySource.java:59)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:84)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:60)
at org.springframework.core.env.AbstractEnvironment.getProperty(AbstractEnvironment.java:511)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$1.getProperty(PropertySourcesPlaceholderConfigurer.java:135)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$1.getProperty(PropertySourcesPlaceholderConfigurer.java:132)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:84)
at org.springframework.core.env.PropertySourcesPropertyResolver.getPropertyAsRawString(PropertySourcesPropertyResolver.java:70)
at org.springframework.core.env.AbstractPropertyResolver$1.resolvePlaceholder(AbstractPropertyResolver.java:207)
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:153)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126)
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:204)
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:178)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$2.resolveStringValue(PropertySourcesPlaceholderConfigurer.java:175)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:801)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:962)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:342)
// SNIP
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.boot.autoconfigure.web.HttpMessageConverters] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1308)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054)
at org.springframework.beans.factory.support.DefaultListableBeanFactory$DependencyObjectFactory.getObject(DefaultListableBeanFactory.java:1419)
at org.springframework.beans.factory.support.DefaultListableBeanFactory$DependencyProvider.get(DefaultListableBeanFactory.java:1436)
at org.springframework.cloud.netflix.feign.support.SpringDecoder.decode(SpringDecoder.java:57)
at feign.SynchronousMethodHandler.decode(SynchronousMethodHandler.java:169)
... 93 common frames omitted

这发生在 @FeignClient(url = "localhost:8080") .将功能区与 @FeignClient("config") 一起使用完全失败:
Caused by: java.lang.NullPointerException
at feign.ribbon.LoadBalancingTarget.apply(LoadBalancingTarget.java:91)
at feign.SynchronousMethodHandler.targetRequest(SynchronousMethodHandler.java:164)
at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:108)
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:96)
at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:92)
at com.sun.proxy.$Proxy26.get(Unknown Source)
at test.MyPropertySourceLocator$1.getProperty(MyPropertySourceLocator.java:32)

我想使用 REST(因此假装)访问配置。可能的解决方法当然是直接使用 feign。

最佳答案

bootstrap 上下文应该是轻量级的(并且可以快速创建),所以它不是一个完整的 @EnableAutoconfiguration .使用 @FeignClient您需要导入 FeignAutoConfiguration (以及任何依赖的东西,这不是 IIRC)。

关于spring-cloud - 是否可以在 BootstrapConfiguration 上使用 @EnableFeignClients?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28628984/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com