【问题标题】:How to enforce a specific Spring Security version dependency in Spring Boot如何在 Spring Boot 中强制执行特定的 Spring Security 版本依赖
【发布时间】:2015-10-08 00:49:56
【问题描述】:

如何保证Spring Security>3.2.1按照这个documentedbug使用?:

class path resource [org/springframework/security/config/annotation/authentication/configurers/GlobalAuthenticationConfigurerAdapter.class] 
cannot be opened because it does not exist

我在POM.xml 中尝试了upgrading it,但没有成功(Intellij 抱怨该版本不存在):

我在 Intellij Maven 设置中的本地存储库路径是正确的。我将鼠标悬停在它的投诉上并选择“更新 Maven 索引”。它尝试更新我的本地存储库,只返回不存在的依赖项。

那么,我还能如何确保找到 GlobalAuthenticationConfigurerAdapter.class

【问题讨论】:

  • 对于初学者,请发布您的 POM,但应该这样做。您可能需要特别依赖相关的实际包,而不仅仅是间接依赖。
  • 使用 spring-boot-starter-security 具有所有正确依赖项的依赖项。也没有 Spring 安全版本 4.0.2,最新的是 4.0.1。但你真的应该使用启动器,而不是自己尝试找出有效的依赖版本。
  • @M.Deinum 你能回答这个问题吗?这是实际的解决方案。

标签: java spring maven spring-mvc intellij-idea


【解决方案1】:

我认为这个问题的当前答案可以在这里找到:

分级

https://docs.spring.io/spring-security/reference/getting-spring-security.html#getting-gradle-boot

例如对于 Spring Security 版本 5.7.0-SNAPSHOT 指定属性

ext['spring-security.version']='5.7.0-SNAPSHOT'

在你的 Gradle 文件中

Maven

https://docs.spring.io/spring-security/reference/getting-spring-security.html#getting-maven-boot

例如对于 Spring Security 版本 5.7.0-SNAPSHOT 指定属性

<properties>
    <!-- ... -->
    <spring-security.version>5.7.0-SNAPSHOT</spring-security.version>
</properties>

还请记住,如果您要尝试公共 Maven 存储库中可能不存在的新构建,您可能必须添加 Spring 自己的存储库,例如 https://repo.spring.io/snapshot

【讨论】:

    【解决方案2】:

    如果您使用的是较旧的 Spring Boot 启动器,但您想要最新的安全性,您可以这样做

     <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.2.RELEASE</version>
    </parent>
    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.security</groupId>
                    <artifactId>spring-security-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>4.1.3.RELEASE</version>
        </dependency>
    

    【讨论】:

      【解决方案3】:

      使用 Spring Boot 时,请使用不同的 Spring Boot Starter 项目来获取适当的依赖项。对于 Spring Security,这意味着添加 spring-boot-starter-security 依赖项以获取所有必要的 Spring Security 依赖项。

      使用启动器将使您免于寻找正确的依赖项和依赖项版本,您将通过这种方式获得一组有效的依赖项。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-05-21
        • 1970-01-01
        • 2019-01-04
        • 2023-04-03
        • 2016-07-29
        • 2017-07-05
        • 1970-01-01
        • 2017-07-24
        相关资源
        最近更新 更多