java - 无法注册 bean 'exampleService.FeignClientSpecification'。Bean 已定义且覆盖已禁用
问题描述
我的假客户端类和应用程序类如下。
@FeignClient(name = "ExampleService", configuration = FeignClientConfig.class, url = "http://localhost:8091")
public interface ExampleClient {
@GetMapping(value = "exampleService/exampleDetails/{id}")
public List<ExampleDTO> getExampleDetails(@PathVariable(name = "id") final Long id);
}
@EnableAutoConfiguration
@EnableScheduling
@SpringBootApplication
@EnableFeignClients(basePackages = {"com.package.example"})
@ComponentScan(basePackages = {"com.package"})
public class ExampleApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(ExampleApplication.class, args);
}
}
在上面的代码中,我收到如下错误
APPLICATION FAILED TO START
Description:
The bean 'ExampleService.FeignClientSpecification' could not be registered. A bean with that name has already been defined and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding = true
首先,项目中只定义了 1 个使用该名称的 feign 客户端。其次,我尝试给它一个上下文 ID,以防万一有一个同名的 bean 被定义在我一定错过的某个地方。
@FeignClient(contextId = "myExampleService", name="ExampleService", configuration = FeignClientConfig.class, url = "http://localhost:8091")
但它又给了我同样的错误
The bean 'myExampleService.FeignClientSpecification' could not be registered. A bean with that name has already been defined and overriding is disabled.
第三,我还尝试通过在 application.properties 文件中提供属性来覆盖 bean
spring.main.allow-bean-definition-overriding = true
但我仍然遇到同样的错误。即使只有 1 个名称可用于 Spring 的应用程序上下文的 bean,为什么我会遇到此问题?
解决方案
如果您定义了超过 1 个具有相同名称的 @FeignClients,也会发生这种情况: 链接
在我的客户中给出唯一的名字为我解决了这个问题
推荐阅读
- javascript - JavaScript 脚本不能同时工作,即使它们彼此无关
- python-3.x - Python:使用 pd.concat 联合多个数据框表
- ios - XCTest - 在自定义坐标上使用捏合手势使用 XCUIElement 进行 UI 测试?
- big-o - Big Oh 表示法中的对数和指数转换
- r - 如果向量 y 的对应值不是“否”,我想用“是”替换向量 x 中的每个值
- vue.js - VueJs:动态折叠(手风琴)
- html - 如何使用 CSS inset 将元素定位在右上角?
- python - python中的call()和__call__()方法有什么区别?
- python - Python 循环中的 .append 正在替换所有元素
- python - 使用win32写入excel文件后,文件不加载