我在@FeignClient
中声明了ea.jar
:
@FeignClient(name = "ea")
public interface AdvertGroupRemoteService {
@RequestMapping(value = "/group/{groupId}")
AdvertGroupVO findByGroupId(@PathVariable("groupId") Integer adGroupId);
}
我将这个jar添加为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依赖项),则此异常消失。
我不知道这个,帮助