springboot启动报错: Consider defining a bean of type ‘XXX‘ in your configuration

编程知识 更新时间:2023-05-02 05:24:21

Consider defining a bean of type ‘XXX’ in your configuration


出现这个错误,要看看你是否用到了某些组件,但是启动类上没加相应的注解。比如说我就是因为在service层用到了@FeignClient注解,但是在启动类上忘了加上@EnableFeignClients注解,才导致的报错,写代码一定要细心啊。



异常信息如下:

Description:

A component required a bean of type 'com.atgugu.springcloud.service.PaymentHystrixService' that could not be found.


Action:

Consider defining a bean of type 'com.atgugu.springcloud.service.PaymentHystrixService' in your configuration.


service层代码如下:

package com.atgugu.springcloud.service;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Component
@FeignClient(value = "CLOUD-PROVIDER-HYSTRIX-PAYMENT")//使用FeignClient作服务调用
public interface PaymentHystrixService {

    @GetMapping(value = "/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id);

    @GetMapping(value = "/payment/hystrix/timeout/{id}")
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id);
}


启动类代码如下:

package com.atgugu.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloudflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableFeignClients//使用FeignClient记得添加@EnableFeignClients注解
@EnableHystrix
public class OrderHystrixMain80 {
    public static void main(String[] args) {
        SpringApplication.run(OrderHystrixMain80.class, args);
    }
}






谢谢观看,我爱这魔幻的代码!



更多推荐

springboot启动报错: Consider defining a bean of type ‘XXX‘ in your configuration

本文发布于:2023-04-26 05:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/3fde201828cefd5a80a2924a7973144a.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:报错   defining   springboot   bean   configuration

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 104371文章数
  • 26212阅读数
  • 0评论数