Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
解決方法:
在application.yml或你項(xiàng)目對(duì)應(yīng)的配置文件中添加如下代碼:
spring:
main:
allow-bean-definition-overriding: true
實(shí)踐驗(yàn)證:
為了驗(yàn)證該配置信息是否會(huì)造成覆蓋問題,現(xiàn)模擬一下情況:
項(xiàng)目中有feign模塊、service_user模塊、service_course模塊;其中feign模塊包含所有feignclient類;service_course模塊導(dǎo)入feign模塊并且額外在自己的模塊中添加一個(gè)feignclient;service_user模塊是被其他兩個(gè)模塊遠(yuǎn)程接口調(diào)用的。如下:
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的控制器調(diào)用:
@RestController
@RequestMapping("/")
public class CourseController {
@Autowired
UserOpenFeignService userOpenFeignService;
@Autowired
UserFeign userFeign;
@GetMapping("/test")
public ResponseUtil test(){
//service_course模塊的本地UserOpenFeignService文件調(diào)用
ResponseUtil user = userOpenFeignService.findUser("5");
return user;
}
@GetMapping("/test1")
public String test1(){
//feign模塊的UserFeign 文件調(diào)用
String user = userFeign.findUser("13");
return user;
}
接著進(jìn)行測試:
?
?至此,可以證明。
?文章來源地址http://www.zghlxwxcb.cn/news/detail-765773.html文章來源:http://www.zghlxwxcb.cn/news/detail-765773.html
?
到了這里,關(guān)于Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definiti的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!