首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在WebSecurityConfigurerAdapter版本2.0.6中解析SpingBoot类

无法在WebSecurityConfigurerAdapter版本2.0.6中解析SpingBoot类
EN

Stack Overflow用户
提问于 2018-10-28 06:07:58
回答 2查看 5K关注 0票数 2

当我试图编写一个配置类时,无法解析WebSecurityConfigurerAdapter类,注释@EnableWebSecurity也是如此。

我认为这是由版本冲突引起的,所以我尝试更改spring启动-安全性的版本。结果表明,类在2.0.6版本中不能扩展,但在2.0.0中可以工作。

那么,在2.0.6中是否有WebSecurityConfigurerAdapter的替代物呢?

这是我的pom.xml

代码语言:javascript
复制
<groupId>com.example</groupId>
<artifactId>registertest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>registertest</name>
<description>Demo login and register for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.6.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>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <!--Version 2.0.6 will cause a conflict, we need to modify the version to 1.5.6-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
        <version>2.0.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!--if you do not want to modify the version above, the following dep is the substitution-->
    <!--<dependency>-->
        <!--<groupId>org.springframework.security</groupId>-->
        <!--<artifactId>spring-security-config</artifactId>-->
        <!--<version>4.2.3.RELEASE</version>-->
    <!--</dependency>-->

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</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>net.sourceforge.nekohtml</groupId>
        <artifactId>nekohtml</artifactId>
    </dependency>
</dependencies>

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-10-28 07:01:48

在spring 2.0.6中,您仍然将使用:

代码语言:javascript
复制
 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

如果您进行了版本升级,您可能在您的.m2存储库中同时拥有这两个版本,而且maven不知道使用哪个版本。

解决方案:请删除.m2文件夹-根据您的操作系统检查它的位置-并且请注意它是一个隐藏的文件夹。

删除spring-boot-starter-security版本并运行命令mvn clean package重新导入所有依赖项。

票数 1
EN

Stack Overflow用户

发布于 2018-10-28 06:57:59

如果您使用的是父版本,则不需要在依赖项中提到它,因为它将自动处理所有所需的兼容版本并加载。

所以只需使用下面没有版本..。

代码语言:javascript
复制
   <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

注意:如果您想要扩展或可以实现WebSecurityConfigurerAdapter,请在2.0.6中使用WebSecurityConfigurerAdapter

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53028844

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档