Spring启动REST API应用程序没有看到OAuth2库

时间:2018-03-31 20:50:13

标签: java spring-boot oauth-2.0

我想使用OAuth2通过身份验证保护我的REST API,但在我的旅程开始时我遇到了一些问题,例如"Cannot resolve symbol 'AuthorizationServerConfigurerAdapter'"在互联网上找不到任何解决方案,所以我问你。我根本无法导入它,并且我写了类似import org.springframework.security.oauth2.client.OAuth2ClientContext;的东西,它说无法解析oauth2。

我的pom.xml文件看起来像:

<groupId>com.bsuir</groupId>
<artifactId>buspark</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>buspark</name>
<description>labs</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>

    <!--SECURITY-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security.oauth2</groupId>
        <artifactId>spring-security-oauth2</artifactId>
    </dependency>
    <!--SECURITY-->

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!--SWAGGER-->
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.8.0</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.8.0</version>
        <scope>compile</scope>
    </dependency>
    <!--SWAGGER-->



    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

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

提前致谢。

2 个答案:

答案 0 :(得分:1)

组ID包含错误。它必须是不带2的oauth。最终版本如下:

<dependency>
    <groupId>org.springframework.security.oauth</groupId>
    <artifactId>spring-security-oauth2</artifactId>
    <version>2.3.6.RELEASE</version>
</dependency>

答案 1 :(得分:0)

我手动下载了库(http://central.maven.org/maven2/org/springframework/security/oauth/spring-security-oauth2/2.3.0.RELEASE/)并将它们安装在&#34;项目设置&#34; - &GT; &#34;库&#34;