Spring Boot 2.0 disable default security
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
In Spring Boot 2.0, if Spring Security is on the classpath, Boot auto-configures a default security setup. That usually means all endpoints become protected, a generated password appears in the logs, and a basic login flow is enabled.
If you want the application completely unsecured for local development or because you plan to provide your own security configuration, you need to either exclude the auto-configuration or replace it with an explicit SecurityFilterChain configuration.
What "Default Security" Means
With Spring Boot 2.0 and Spring Security present, Boot provides a fallback configuration. You often see behavior like:
- all HTTP endpoints require authentication
- a generated password is logged at startup
- form login or HTTP Basic is enabled automatically
This is useful as a safe default, but it is rarely what you want for a real application beyond the initial bootstrap stage.
Option 1: Exclude Security Auto-Configuration
If you truly want Spring Boot not to set up default security at all, exclude the security auto-configuration classes.
This is the blunt instrument approach. It turns off Boot's default servlet security setup and, if Actuator is involved, avoids the management endpoint security auto-configuration too.
Option 2: Provide Your Own Security Configuration
A more controlled approach is to keep Spring Security and define your own rules explicitly.
This approach is usually better than excluding everything, because it makes the application's security intent explicit and leaves room to tighten rules later.
Why Not Just Remove the Dependency?
If the application does not need Spring Security at all, the simplest option is often to remove the dependency from the project rather than disabling its behavior after loading it.
That said, if other parts of the application need security classes or you plan to add custom rules shortly, keeping the dependency and overriding the default behavior can be reasonable.
Actuator Endpoints Need Extra Attention
In Spring Boot 2.0, Actuator endpoints can be affected separately. If you disable only general web security but forget management security configuration, Actuator behavior may still surprise you.
That is why the auto-configuration exclusion example commonly includes both SecurityAutoConfiguration and ManagementWebSecurityAutoConfiguration.
Development Versus Production
Disabling default security can make local development easier, but it is not a production strategy. If the app is meant to be reachable by users or other systems, write an explicit security policy instead of leaving everything open.
Treat "disable default security" as either:
- a local development convenience
- a transition step before custom security rules
- a deliberate choice for an internal non-sensitive service
It should not become an accidental permanent state.
Common Pitfalls
- Excluding security auto-configuration when the real need was just to permit a few endpoints.
- Forgetting that Actuator endpoints may have separate management security behavior.
- Disabling everything in development and then accidentally shipping the same config to production.
- Keeping Spring Security on the classpath and being surprised when Boot auto-configures it.
- Using broad exclusions when an explicit custom
SecurityFilterChainwould be clearer.
Summary
- Spring Boot 2.0 enables a default security setup when Spring Security is on the classpath.
- You can disable it by excluding
SecurityAutoConfiguration, and oftenManagementWebSecurityAutoConfigurationtoo. - A better long-term approach is usually to provide your own security configuration explicitly.
- If you do not need Spring Security at all, removing the dependency may be simplest.
- Be careful not to turn a development shortcut into an unintended production policy.
Related reading
- Spring Boot Actuator hides property values in env endpoint
- Spring Boot Authentication for Integration Tests
- Spring Boot CORS filter - CORS preflight channel did not succeed
- Spring Boot Dev Tools Turning them off for production?
- Spring boot 2.1 bean override vs. Primary
- Spring boot 2.4.0 The type HandlerInterceptorAdapter is deprecated
- Spring Boot enabling CORS by application.properties
- Spring Boot /h2-console throws 403 with Spring Security 1.5.2

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.