У меня есть объявление @FeignClient
в ea.jar
:
@FeignClient(name = "ea")
public interface AdvertGroupRemoteService {
@RequestMapping(value = "/group/{groupId}")
AdvertGroupVO findByGroupId(@PathVariable("groupId") Integer adGroupId);
}
Я добавил эту банку как зависимость от maven, а затем ввел ее:
@RestController
public class TestCtr {
@Autowired
private AdvertGroupRemoteService advertGroupRemoteService;
}
У меня всегда было NoSuchBeanDefinitionException
:
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private cn.com.sina.alan.ms.ea.api.service.AdvertGroupRemoteService cn.com.sina.alan.gateway.controller.TestCtr.advertGroupRemoteService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [cn.com.sina.alan.ms.ea.api.service.AdvertGroupRemoteService] 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.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
... 22 common frames omitted
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [cn.com.sina.alan.ms.ea.api.service.AdvertGroupRemoteService] 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:1373) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
... 24 common frames omitted
Но если я перемещу объявление @FeignClient
в тот же проект (не добавлен как зависимость jar), это исключение исчезнет.
понятия не имею об этом, помогите
@EnableFeignClients
по умолчанию сканирует только иерархию пакетов того класса, в котором он используется. Чтобы сканировать за пределами пакета, вы должны быть явными. - person spencergibb   schedule 10.08.2016