Inject @AuthenticationPrincipal when unit testing a Spring REST controller
问题 I am having trouble trying to test a REST endpoint that receives an UserDetails as a parameter annotated with @AuthenticationPrincipal. It seems like the user instance created in the test scenario is not being used, but an attempt to instantiate using default constructor is made instead: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.andrucz.app.AppUserDetails]: No default constructor found; REST endpoint: @RestController @RequestMapping("/api/items") class