admin管理员组文章数量:1794759
springboot启动报错: Consider defining a bean of type ‘XXX‘ in your configuration
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); } }谢谢观看,我爱这魔幻的代码!
本文标签: 报错definingSpringBootbeanconfiguration
版权声明:本文标题:springboot启动报错: Consider defining a bean of type ‘XXX‘ in your configuration 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686556759a81544.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论