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

Spring从3.1.1.RELEASE升级到3.2.0.RELEASE启动报错求助

问题分析

Spring 3.2.0.RELEASE升级了内置的ASM依赖版本(至ASM 4.x),但你使用的Spring Security 3.1.4.RELEASE依赖的是旧版ASM(ASM 3.x),两者版本不兼容,导致类加载时org.springframework.asm.ClassReader初始化失败,进而触发BeanDefinitionStoreException。Repository类因为会被Spring容器扫描处理、执行字节码操作,所以最先暴露该冲突问题。

解决方案
  • 优先升级Spring Security版本:将Spring Security升级到与Spring 3.2.x兼容的3.2.x系列(比如3.2.10.RELEASE),该版本已适配Spring 3.2的ASM版本。修改pom.xml中的依赖版本:
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>3.2.10.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>3.2.10.RELEASE</version>
    </dependency>
    
    同时建议将spring-security.xml的xsd版本同步升级到3.2,保持配置与依赖版本一致:
    <beans:beans xmlns="http://www.springframework.org/schema/security"
                 xmlns:beans="http://www.springframework.org/schema/beans"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://www.springframework.org/schema/beans
                                     http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
                                     http://www.springframework.org/schema/security
                                     http://www.springframework.org/schema/security/spring-security-3.2.xsd">
    
  • 强制统一ASM版本(备选方案):如果暂时无法升级Spring Security,可在pom.xml中强制指定ASM版本为Spring 3.2使用的4.0,覆盖Spring Security依赖的旧版:
    <dependency>
        <groupId>org.ow2.asm</groupId>
        <artifactId>asm</artifactId>
        <version>4.0</version>
    </dependency>
    <dependency>
        <groupId>org.ow2.asm</groupId>
        <artifactId>asm-commons</artifactId>
        <version>4.0</version>
    </dependency>
    
    注意:此方法存在潜在兼容性风险,仅作为临时过渡方案使用。
补充说明

跳过测试能构建成功,是因为构建阶段未触发Spring容器初始化和类字节码扫描;而启动时容器需要处理Repository等Bean的定义,才会触发ASM相关操作,进而暴露版本冲突问题。

内容的提问来源于stack exchange,提问作者jack

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 23:12:30