Testing security in Spring Boot 1.4

前端 未结 1 826
北荒
北荒 2020-12-04 02:01

I\'m trying to test @WebMvcTest with custom security settings defined in SecurityConfig class:

@Configuration
@EnableWebSecurity
p         


        
相关标签:
1条回答
  • 2020-12-04 02:24

    WebMvcTest is only going to load your controller and nothing else (that's why we call that slicing). We can't figure out which part of your configuration you want and which one you don't. If the security config isn't on your main @SpringBootApplication you'll have to import it explicitly. Otherwise, Spring Boot is going to enable default security settings.

    If you're using something like OAuth, that's a good thing though because you really don't want to start using that for a mock test. What happens if you add @Import(SecurityConfig.class) to your test?

    0 讨论(0)
提交回复
热议问题