title: Spring boot jUnit test fails because of "org.springframework.beans.factory.NoSuchBeanDefinitionException"
body: <p>I'm writing an end-to-end test for the following class in my Spring boot project, but I receive <code>org.springframework.beans.factory.NoSuchBeanDefinitionException</code> error because <code>No qualifying bean of type 'com.boot.cut_costs.service.CustomUserDetailsService' available</code>.</p>
  
  <pre><code>@RestController
  public class AuthenticationController {
  
      @Autowired
      protected AuthenticationManager authenticationManager;
      @Autowired
      private CustomUserDetailsService userDetailsServices;
      @Autowired
      private UserDetailsDtoValidator createUserDetailsDtoValidator;
  
      @RequestMapping(value = "/signup", method = RequestMethod.POST)
      public void create(@RequestBody UserDetailsDto userDetailsDTO, HttpServletResponse response, BindingResult result) {
          // ...
          userDetailsServices.saveIfNotExists(username, password, name);
          // ...
          if (authenticatedUser != null) {
              AuthenticationService.addAuthentication(response, authenticatedUser.getName());
              SecurityContextHolder.getContext().setAuthentication(authenticatedUser);
          } else {
              throw new BadCredentialsException("Bad credentials provided");
          }
      }
  }
  </code></pre>
  
  <p>Test class:</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @WebMvcTest(AuthenticationController.class)
  public class AuthenticationControllerFTest {
  
      @Autowired 
      private MockMvc mockMvc;
  
      @MockBean
      private AuthenticationManager authenticationManager;
  
      @Test
      public void testCreate() throws Exception {
          Authentication authentication = Mockito.mock(Authentication.class);
          Mockito.when(authentication.getName()).thenReturn("DUMMY_USERNAME");
          Mockito.when(
                  authenticationManager.authenticate(Mockito
                      .any(UsernamePasswordAuthenticationToken.class)))
                  .thenReturn(authentication);
  
          //....
          RequestBuilder requestBuilder = MockMvcRequestBuilders
                  .post("/signup")
              .accept(MediaType.APPLICATION_JSON).content(exampleUserInfo)
                  .contentType(MediaType.APPLICATION_JSON);
  
          MvcResult result = mockMvc.perform(requestBuilder).andReturn();
  
          MockHttpServletResponse response = result.getResponse();
      }
  }
  </code></pre>
  
  <p>I think this error happens because it in the test environment the spring context isn't loaded the same way as in dev/production environment. How should I fix this issue ?</p>
  
  <p><strong>Edit 1</strong></p>
  
  <p>My Spring boot application entry point is <code>App.java</code>:</p>
  
  <pre><code>@SpringBootApplication
  public class App {
      public static void main(String[] args) {
          SpringApplication.run(App.class, args);
      }
  }
  </code></pre>