Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
解决方法:
在application.yml或你项目对应的配置文件中添加如下代码:
spring: main: allow-bean-definition-overriding: true
实践验证:
为了验证该配置信息是否会造成覆盖问题,现模拟一下情况:
项目中有feign模块、service_user模块、service_course模块;其中feign模块包含所有feignclient类;service_course模块导入feign模块并且额外在自己的模块中添加一个feignclient;service_user模块是被其他两个模块远程接口调用的。如下:
feign模块拥有如下文件UserFeign :
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @FeignClient(name = "service-user") public interface UserFeign { @GetMapping("/admin/select/{user_id}") public String findUser(@PathVariable String user_id); }
service_course模块拥有如下文件UserOpenFeignService :
@FeignClient(name = "service-user") public interface UserOpenFeignService { @GetMapping("/admin/select/{user_id}") public ResponseUtil findUser(@PathVariable String user_id); }
接着由service_course的控制器调用:
@RestController @RequestMapping("/") public class CourseController { @Autowired UserOpenFeignService userOpenFeignService; @Autowired UserFeign userFeign; @GetMapping("/test") public ResponseUtil test(){ //service_course模块的本地UserOpenFeignService文件调用 ResponseUtil user = userOpenFeignService.findUser("5"); return user; } @GetMapping("/test1") public String test1(){ //feign模块的UserFeign 文件调用 String user = userFeign.findUser("13"); return user; }
接着进行测试:
至此,可以证明。