You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot启动失败:mvcHandlerMappingIntrospectorRequestTransformer Bean重名求助

解决Spring Boot 3.2.1 + Spring Native启动时的Bean冲突问题

错误场景

启动应用时触发如下启动失败错误:

Microsoft Windows [Version 10.0.22631.2861]
(c) Microsoft Corporation. All rights reserved.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.2.1)

2024-01-09T23:07:03.438+07:00  INFO 34652 --- [       

***************************
APPLICATION FAILED TO START
***************************

描述:
无法注册bean 'mvcHandlerMappingIntrospectorRequestTransformer'。已存在同名bean,且禁用了覆盖机制。

操作建议:
考虑重命名其中一个bean,或通过设置spring.main.allow-bean-definition-overriding=true启用覆盖机制。

解决方法

方法1:启用Bean定义覆盖机制

在配置文件中添加以下配置快速解决冲突:

  • 若使用application.properties:
spring.main.allow-bean-definition-overriding=true
  • 若使用application.yml:
spring:
  main:
    allow-bean-definition-overriding: true

注意:仅在确认两个同名Bean的功能逻辑一致时使用,否则可能引发未知业务异常。

方法2:重命名冲突Bean

如果不想启用覆盖机制,可手动调整Bean注册逻辑:

  1. 定位冲突Bean的自动注册源(通常来自Spring Security或Spring MVC的自动配置类)
  2. 在启动类上排除对应的自动配置类,例如:
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
public class YourApplication {
    public static void main(String[] args) {
        SpringApplication.run(YourApplication.class, args);
    }
}
  1. 手动创建自定义Bean并指定新名称,确保逻辑与原Bean一致:
@Bean("customMvcHandlerMappingIntrospectorRequestTransformer")
public RequestTransformer customMvcHandlerMappingIntrospectorRequestTransformer(MvcHandlerMappingIntrospector introspector) {
    return new MvcHandlerMappingIntrospectorRequestTransformer(introspector);
}

方法3:修复版本兼容性问题

该冲突大概率是Spring Boot 3.2.1与Spring Native、Spring Security的版本适配问题,可尝试:

  • 升级Spring Native至适配Spring Boot 3.2.x的最新版本
  • 移除手动指定的Spring Security版本,依赖Spring Boot的默认依赖管理来保证版本一致性

内容的提问来源于stack exchange,提问作者Đỗ Như Vỹ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 18:33:20