解决 The bean 'xxx', defined in class path resource [], could not be registered. A bean with that name has already been defined in file []and overriding is disabled.

问题:

在实现短信发送拦截功能时,创建了 PassportInterceptor 验证码拦截器类,使用了@Conponent注解;

同时创建了 InterceptorConfig 拦截器配置类,使用了@Conponent注解,并使用@Bean注解创建了 PassportInterceptor 构造器。代码如下:

启动后报错:

解决:

在 application.yml 配置中启用 beans 覆盖机制 

spring.main.allow-bean-definition-overriding=true

 

posted @ 2023-03-15 16:18  UpZhou  阅读(1094)  评论(0编辑  收藏  举报