我想使用一个PropertySourceLocator
必须在引导期间注册的假客户端。我有以下内容spring.factories
:
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
test.PropertiesConfiguration
和
@Configuration
@EnableFeignClients
public class PropertiesConfiguration {
@Bean
public PropertySourceLocator propertySourceLocator() {
return new MyPropertySourceLocator();
}
}
feign 客户端自动装配到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。