Feign: Spring не может автоматически подключить компонент @FeignClient в файле jar

У меня есть объявление @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), это исключение исчезнет.

понятия не имею об этом, помогите


person Neo    schedule 10.08.2016    source источник
comment
Похоже, ваше сканирование пути к классам аннотаций в Spring не включает пакет, в котором находится ваш FeignClient.   -  person gregwhitaker    schedule 10.08.2016
comment
@gregwhitaker Проблема не в пакете. Я обнаружил, что эта ссылка помогает: stackoverflow.com/ вопросы/30241198/   -  person Neo    schedule 10.08.2016
comment
Этот другой вопрос решил вашу проблему?   -  person Shawn Clark    schedule 10.08.2016
comment
@ShawnClark Да, это так. Но я не знаю, почему   -  person Neo    schedule 10.08.2016
comment
@Neo @EnableFeignClients по умолчанию сканирует только иерархию пакетов того класса, в котором он используется. Чтобы сканировать за пределами пакета, вы должны быть явными.   -  person spencergibb    schedule 10.08.2016
comment
@spencergibb Спасибо, понял   -  person Neo    schedule 11.08.2016