微服务在使用OpenFeign遇到@Resouce注入失败

在使用openfeign遇到的注入失败

检查下后端通过地址是否能获取数据在后端通过地址可以获取到数据

在这里插入图片描述
但是在前端工程中却无法通过地址得到数据,一直报以下的错误

There was an unexpected error (type=Internal Server Error, status=500).
Error creating bean with name 'indexController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.slg.api.ContentClient' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}
通过这个错可以知道是注入的问题,找到注入的地方,发现写了@Resouce
	@Resource
    ContentClient contentClient;

    @RequestMapping({"/","/index"})
    public String index(Model model){
        getContents(model);
        return "index";
    }
    public void getContents(Model model){
        List<Content> lunbo_content = contentClient.getContentsByCategoryId(1);
        model.addAttribute("lunbo_content",lunbo_content);

    }

并且没有报错,于是跑到启动类中查看,发现注解使用错误

@SpringBootApplication
@EnableEurekaClient
@FeignClient
public class ProtalApp10250 {
    public static void main(String[] args) {
        System.out.println("前端展示启动10250");
        SpringApplication.run(ProtalApp10250.class,args);
    }
}

应该把注解@FeignClient替换成@EnableFeignClients
再次启动就发现ok了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值