今天在写微服务项目,启动auth
服务时,SpringBoot
报了 UnsatisfiedDependencyException
异常,日志记录如下:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘tokenController’: Unsatisfied dependency expressed through field ‘sysLoginService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘sysLoginService’: Unsatisfied dependency expressed through field ‘remoteUserService’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.anyCcCN.sjm.api.system.RemoteUserService’: Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: No fallbackFactory instance of type class org.anyCcCN.sjm.api.system.factory.RemoteUserFallbackFactory found for feign client remoteUserService
经过排除发现在SysLoginService
中添加 RemoteUserService
接口后就会导致报错
@Component
public class SysLoginService {
@Autowired
private RemoteUserService remoteUserService;
public String test() {
System.out.println("auth " );
return remoteUserService.test();
}
}
原因是RemoteUserService
接口的实现类并没有注入到 spring
容器中,所以在使用@Autowired
注解获取接口时就会报错。