Field feignDeptClientService in com.cloud.controller.DeptController

feign的初始话的时候的错误,显示service注入失败
理论上来说只要在启动类上

@SpringBootApplication
@EnableFeignClients(basePackages = {"com.cloud"})//这个来骚描包
//@ComponentScan("com.cloud")这个加了报错,但是有人说没事,我没试过
public class SpringcloudConsumerDeptFeign8080Application {

    public static void main(String[] args) {
        SpringApplication.run(SpringcloudConsumerDeptFeign8080Application.class, args);
    }

}

然后重点来了,上面的代码我都要改烂了都没变化,网上一般也就是上面的改法
就差那么一点点,
是的我没放弃
仔细观察发现,导的包好像不对
假如你导的是

import org.springframework.cloud.netflix.feign.FeignClient;

那就错啦,换成下面的试试

import org.springframework.cloud.openfeign.FeignClient;

另外服务上最好对应上对应的服务名

@FeignClient(value = "SPRINGCLOUD-PROVIDER-DEPT")
@Component
public interface FeignDeptClientService {...}

你可能感兴趣的:(springcloud)