Spring Boot Microservices – Spring Security – ServiceTest and ControllerTest for JUnit throwing java.lang.StackOverflowError

The error is most likely caused by declaring the AuthenticationManager as a @Bean. Try this in your test class:

private AuthenticationManager _authenticationManager;

That said, the Spring Security team does not recommend exposing the AuthenticationManager in this way, see the comment in Spring issue #29215

Leave a Comment