今天在写微服务项目,启动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注解获取接口时就会报错。

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐