0

I built a new Spring Boot project using Spring Initializr (at https://start.spring.io).

I included a variety of things including Spring Security because I will want it later.

I have a @RestController with a @GetMapping method. Everything works great. The only problem is when I hit the URL I am directed to the Spring Security login form (where I enter "User" and the password generated at app startup).

My question is, how can I turn off Spring Security for now so I don't get the login screen? I don't want to remove Spring Security from my project because I'll probably want it later.

Here's what I think are the relevant parts of my pom.xml file ...

<?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>

/*** ... ***/
AvaTaylor
  • 623
  • 4
  • 16
  • Does this answer your question? [Spring boot Security Disable security](https://stackoverflow.com/questions/23894010/spring-boot-security-disable-security) – albertjtan Apr 14 '21 at 01:25

2 Answers2

1

You could just comment out the Spring Security dependency in your pom.xml file. If you have a file for the security, you may also rename it by adding "." dot from the start of filename

Rye
  • 445
  • 4
  • 15
1

You could add a configure class extends WebSecurityConfigurerAdapter

Zlatanlong
  • 11
  • 1