Search code examples
springspring-bootdebuggingintellij-idea

Unauthorized Error while Trying to Debug Spring Boot Rest Application


I'm developing a Spring Boot application with Rest Controllers.

When I try to debug application with Intellij IDEA, by right click MyApplication>Debug or Run>Debug, the application starts up and debugger says it's connected. But none of the breakpoints inside my controllers are getting triggered, and all requests start to fail with 401 unauthorized. If I run without debugging, everything works fine.

If something rejects all incoming requests with status 401, it's the reason why breakpoints are not triggered. My code is never executed. But why the requests fail with 401 then in the debug mode?


Solution

  • Changing @SpringBootApplication annotation of the main class as following solves the issue.

    @SpringBootApplication(exclude = { SecurityAutoConfiguration.class })
    

    This excludes and disables Spring Boot's auto configurations about security. It tries to protect the API with a default user and generated password.

    But I still cannot understand why this security auto configuration only gets activated while debugging and keeps disabled while running normally.