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

Spring Boot接口请求返回500错误,是否因版本依赖冲突导致?

问题描述

调用接口时收到500 Internal Server Error响应,控制台输出Spring Boot异常(仅展示开头部分),项目使用Spring Security做API授权,想确认该问题是否与pom.xml中Spring Boot和Spring Security的版本有关。

异常栈信息

at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.22.jar:5.3.22]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) ~[spring-aop-5.3.22.jar:5.3.22]
at com.sun.proxy.$Proxy120.authenticate(Unknown Source) ~[na:na]
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:201) ~[spring-security-core-5.7.2.jar:5.7.2]
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter$AuthenticationManagerDelegator.authenticate(WebSecurityConfigurerAdapter.java:514) ~[spring-security-config-5.7.2.jar:5.7.2]
at sun.reflect.GeneratedMethodAccessor54.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_333]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_333]

pom.xml内容

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>policymanagementsystem</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>policymanagementsystem</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>
         <dependency>
   <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>
  <!--<dependency>
     <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-config</artifactId>
    <version>5.2.1.RELEASE</version> 
</dependency> -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>
        <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-validation</artifactId>
  </dependency>
  <dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.13.3</version>
</dependency>
  <dependency>
     <groupId>org.passay</groupId>
       <artifactId>passay</artifactId>
      <version>1.6.0</version>
</dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <!-- <version>5.4.2.Final</version> -->
        </dependency>
        
   <!--  <dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-core</artifactId>
    <version>5.7.2</version> 
    </dependency>  -->
    <dependency>
    <groupId>io.jsonwebtoken</groupId>
    <artifactId>jjwt</artifactId>
    <version>0.9.1</version>
</dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <!-- <version>5.4.2.Final</version> -->
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <!-- <version>5.1.5.RELEASE</version> -->
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-aop -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aop</artifactId>
    <version>5.3.22</version>
</dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        
         </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
分析与解决方案

从配置和异常信息来看,版本不兼容确实可能是导致这个500错误的原因,具体问题出在以下几点:

  • 手动指定Spring组件版本破坏依赖管理:你用了Spring Boot 2.7.2作为父依赖,它已经内置了一套经过兼容性验证的Spring生态版本(包括Spring Security 5.7.2、Spring AOP 5.3.22等),但手动指定spring-aop版本的做法风险很高,后续若修改Boot版本却不同步组件版本,极易引发冲突。
  • 冗余依赖存在隐患:重复引入jjwt依赖,虽版本相同,但冗余可能导致运行时不可预知问题;注释掉的spring-security-config(5.2.1.RELEASE)与当前Boot配套的5.7.2版本差异极大,若不小心启用会直接触发严重冲突。
  • 异常指向认证流程问题:异常栈显示在ProviderManager.authenticate调用时出错,这是Spring Security认证核心环节。若版本不兼容,AOP代理可能无法正确处理认证切面,导致反射调用失败抛出500错误。

修复建议

  1. 移除所有手动指定的Spring组件版本,依赖Spring Boot父依赖的版本管理即可,比如删掉spring-aop的版本号。
  2. 清理冗余依赖,删除重复的jjwt依赖。
  3. 确保Spring Security版本与Boot完全匹配,不需要手动指定任何Spring Security相关组件版本,spring-boot-starter-security已包含所有必要模块。
  4. 补充完整的异常栈信息,找到最顶部的Caused by内容,能直接定位具体错误原因(如类找不到、方法调用失败等)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 10:25:35