【问题标题】:How do I turn off Spring Security in my new Spring Boot project?如何在我的新 Spring Boot 项目中关闭 Spring Security?
【发布时间】:2021-07-09 01:20:39
【问题描述】:

我使用 Spring Initializr(https://start.spring.io)构建了一个新的 Spring Boot 项目。

我包括了很多东西,包括 Spring Security,因为我以后会想要它。

我有一个 @RestController 和一个 @GetMapping 方法。一切都很好。唯一的问题是当我点击 URL 时,我被定向到 Spring Security 登录表单(我在其中输入“用户”和应用程序启动时生成的密码)。

我的问题是,我现在怎样才能关闭 Spring Security,这样我就看不到登录屏幕了?我不想从我的项目中删除 Spring Security,因为我以后可能会想要它。

我认为这是我的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>2.4.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

/*** ... ***/

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</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>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </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>

/*** ... ***/

【问题讨论】:

标签: spring-boot spring-security


【解决方案1】:

您可以在 pom.xml 文件中注释掉 Spring Security 依赖项。如果您有安全文件,您也可以通过添加“.”来重命名它。文件名开头的点

【讨论】:

    【解决方案2】:

    您可以添加一个配置类扩展 WebSecurityConfigurerAdapter

    【讨论】:

    • 您应该更具体地了解如何配置它,并可选择提供一些参考。
    猜你喜欢
    • 2020-06-19
    • 2022-06-12
    • 2017-03-06
    • 2019-12-22
    • 2018-08-02
    • 2015-12-18
    • 2016-12-15
    • 2017-10-31
    • 2020-07-02
    相关资源
    最近更新 更多