Spring Framework 的 spring-core 和 Spring Security 兼容版本

发布于:2025-05-22 ⋅ 阅读:(21) ⋅ 点赞:(0)

Spring Framework 的 spring-core 和 Spring Security 兼容版本

Spring Framework 的 spring-core 和 Spring Security 的版本需要保持兼容性,尤其是在旧版本(如 Spring 4.x)中。以下是它们的版本对应关系:


Spring 4.x (spring-core 4.x) 对应的 Spring Security 版本

Spring Framework (spring-core) Spring Security 兼容版本 备注
4.0.x 3.2.x 最低要求 Spring Security 3.2.0
4.1.x 3.2.x - 4.0.x 4.0.x 是 Spring 4.1+ 的推荐版本
4.2.x 4.0.x - 4.1.x 4.1.x 支持更多新特性
4.3.x (Spring Boot 1.4-1.5) 4.1.x - 4.2.x 推荐 4.2.x

注意:Spring Security 4.x 仍然兼容 Spring Framework 4.x,但 Spring Security 5.x 需要 Spring 5+。


Spring 5.x (spring-core 5.x) 对应的 Spring Security 版本

Spring Framework (spring-core) Spring Security 兼容版本
5.0.x 5.0.x
5.1.x 5.1.x - 5.2.x
5.2.x 5.2.x - 5.3.x
5.3.x (Spring Boot 2.4+) 5.4.x - 5.6.x
6.x 6.x

常见组合示例

  1. Spring Boot 1.5.x (Spring 4.3.x)

    • spring-core: 4.3.x
    • spring-security: 4.2.x(推荐)
    • Maven 依赖示例:
      <dependency>
          <groupId>org.springframework.security</groupId>
          <artifactId>spring-security-web</artifactId>
          <version>4.2.18.RELEASE</version>
      </dependency>
      
  2. Spring Boot 2.7.x (Spring 5.3.x)

    • spring-core: 5.3.x
    • spring-security: 5.7.x
    • Maven 依赖示例:
      <dependency>
          <groupId>org.springframework.security</groupId>
          <artifactId>spring-security-web</artifactId>
          <version>5.7.10</version>
      </dependency>
      

如何检查版本兼容性?

  1. Spring Security 官方文档
    参考 Spring Security Releases官方文档
  2. Spring Boot 的依赖管理
    如果使用 Spring Boot,可以直接继承其管理的版本(无需手动指定):
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.22.RELEASE</version> <!-- 或 2.x.x -->
    </parent>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    

总结

  • Spring 4.x → 使用 Spring Security 3.2.x - 4.2.x(推荐 4.2.x)。
  • Spring 5.x → 使用 Spring Security 5.x
  • Spring 6.x → 必须使用 Spring Security 6.x

如果需要更精确的版本,建议查阅 Spring Security 官方兼容性文档