Yes, you can disable Spring Security auto-configuration for a test in a Spring Boot application. There are several ways to achieve this, but I will provide you with some common approaches. 1. **Approach 1**: Exclude `SecurityAutoConfiguration` You can exclude the `SecurityAutoConfiguration` class from autoconfiguration in your test class. This approach ensures Spring Security is not loaded for the test. ```java import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest(classes = YourApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, excludeAutoConfiguration = SecurityAutoConfiguration.class) public class YourTestClass { // Your test methods } ``` In this code: * `YourApplication.class` should be replaced with the main application class of your Spring Boot application. 2. **Approach 2**: Use `@AutoConfigureMockMvc` with `addFilters = false` You can also disable Spring Security filters for your tests by using the `@AutoConfigureMockMvc` annotation with the `addFilters` attribute set to `false`. This method is particularly useful if you want to test with Spring Security disabled but still use Spring MVC. ```java import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @AutoConfigureMockMvc(addFilters = false) public class YourTestClass { // Your test methods } ``` 3. **Approach 3**: Using Test Configuration You can create a specific test configuration that excludes the security autoconfiguration. ```java import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; import org.springframework.boot.test.context.TestConfiguration; @TestConfiguration @ImportAutoConfiguration(exclude = SecurityAutoConfiguration.class) public class TestConfig { } ``` Then, you can include this configuration in your test class: ```java import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @Import(TestConfig.class) public class YourTestClass { // Your test methods } ``` 4. **Approach 4**: Use a Custom Test Configuration You can create a custom test configuration class that overrides the security-related beans. This approach can be useful if you want more fine-grained control. ```java import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.annotation.Bean; @TestConfiguration public class TestSecurityConfig { @Bean public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception { http.authorizeRequests(authorizeRequests -> authorizeRequests.anyRequest().permitAll() ); return http.build(); } } ``` In your test class, you can then import this custom configuration: ```java import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @Import(TestSecurityConfig.class) public class YourTestClass { // Your test methods } ``` 5. **Approach 5**: Conditional Autoconfiguration If your application uses Spring Profiles, you can conditionally enable or disable Spring Security based on the active profiles. This approach can be useful if you want to toggle Spring Security for specific test profiles. In your test configuration class: ```java import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @Configuration @ConditionalOnProperty(name = "security.enabled", havingValue = "false") public class SecurityDisabledConfig { } ``` In your `application.properties` or `application.yml` for the test profile: ```yaml security.enabled=false ``` This will conditionally disable Spring Security when the `security.enabled` property is set to `false` in the test profile. By using any of these approaches, you can efficiently disable Spring Security autoconfiguration for your test classes and perform tests without security constraints. Choose the method that best suits your testing requirements.