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 官方兼容性文档

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐