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;
}
接着进行测试:
至此,可以证明。
文章来源地址https://www.toymoban.com/news/detail-765773.html文章来源:https://www.toymoban.com/news/detail-765773.html
到了这里,关于Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definiti的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!