title: Beans in Spring test
body: <p>I have one user controller.</p>
  
  <p>User controller: </p>
  
  <pre><code>@CrossOrigin(origins = "*", allowedHeaders = "*")
  @RestController
  @RequestMapping("users")
  public class UserRestController {
  
  private final UserService userService;
  
  public UserRestController(final UserService userService) {
      this.userService = userService;
  }
  
  @GetMapping()
  public User getInfo(
          final @AuthenticationPrincipal UserDetails userDetails
  ) {
      return userService.findByUsername(userDetails.getUsername());
  }
  
  @PutMapping()
  public User update(
          final @AuthenticationPrincipal UserDetails userDetails,
          final @RequestBody User user
  ) {
      User userInSystem = userService.findByUsername(
              userDetails.getUsername()
      );
      return userService.update(user, userInSystem);
  }
  }
  </code></pre>
  
  <p>I make some test for him.</p>
  
  <p>Test User controller: </p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest(classes = ApplicationArguments.class)
  @Configuration // this annotation can be removed, the error will remain the same
  @EnableAutoConfiguration //previous comment
  public class TestUserRestController {
  
  @Autowired
  private UserRestController userRestController;
  
  @Test
  public void Test() {
      assertThat(userRestController).isNotNull();
  }
  }
  </code></pre>
  
  <p>And in the end, I have an error when running the test:</p>
  
  <blockquote>
    <p>org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.daniil.ostrouh.notes.TestUserRestController': Unsatisfied dependency expressed through field 'userRestController'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.daniil.ostrouh.notes.rest.UserRestController' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}</p>
  </blockquote>
  
  <p>Please tell me what I'm doing wrong</p>
  
  <p><strong>Updates</strong>
  Project Structure: <a href="https://i.stack.imgur.com/p3fVz.png" rel="nofollow noreferrer">Project Structure</a></p>