未找到 ProviderSettings 类,它显示无法解析符号 ProviderSettings

问题描述 投票:0回答:2

我是 Spring Boot 空间的新手。我正在按照教程学习创建 OAuth 身份验证服务器。

在配置

AuthorizationServerConfig.java
时,讲师从包“org.springframework.security.oauth2.server.authrization.config”导入“ProviderSettings”类

但是,我没有从该特定包中获得该类。

我是否缺少任何依赖项?还是现在没有课程?

参考文献1:错误点。无法解析符号 ProviderSettings

@Bean
    public ProviderSettings providerSettings(){
        return ProviderSettings.builder()
                .issuer("http://auth-server:9000")
                .build();
    }

参考2:pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>3.0.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>np.com.oskarshrestha</groupId>
    <artifactId>Oauth-authorization-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Oauth-authorization-server</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-oauth2-authorization-server</artifactId>
            <version>1.0.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>


I tried to find the correct import for the required class i.e. 'ProviderSettings'
Cross checked dependencies.
spring authentication spring-security server classnotfoundexception
2个回答
29
投票

你不会相信我,但我几分钟前刚刚解决了这个问题。看起来该指南使用的是过时版本

spring-security-oauth2-authorization-server
他们改名了

ProviderSettings to AuthorizationServerSettings

https://github.com/spring-projects/spring-authorization-server/issues/864

https://github.com/spring-projects/spring-authorization-server/issues/681

https://github.com/spring-projects/spring-authorization-server/issues/986

他们应该将这些更改添加到文档中或使其更加清晰(IMO)


0
投票

我猜你指的是这个人:https://youtu.be/zvR-Oif_nxg?t=32043 .

其实他不太清楚自己在做什么,添加样板代码。

无论如何,您可以使用 Spring 的参考指南,其中显示了授权服务器的工作示例: https://docs.spring.io/spring-authorization-server/reference/getting-started.html#defining-required-components

@Bean
public AuthorizationServerSettings authorizationServerSettings() {
    return AuthorizationServerSettings
            .builder()
            .issuer("http://auth-server:9000")
            .build();
}
© www.soinside.com 2019 - 2024. All rights reserved.