title: Spring boot test "No qualifying bean of type available"
body: <p>I'm quite a newbie to Spring boot, but here's the problem I'm facing now:</p>
  
  <pre><code>// Application.java
  public class Application {
    public static void main(String[] args) {
      SpringApplication.run(Application.class, args);
    }
  
    @Autowired
    private Cluster cluster = null;
  
    @PostConstruct
    private void migrateCassandra() {
      Database database = new Database(this.cluster, "foo");
      MigrationTask migration = new MigrationTask(database, new MigrationRepository());
      migration.migrate();
    }
  }
  </code></pre>
  
  <p>So basically, I'm trying to bootstrap a spring application, and after that, do some cassandra migrations.</p>
  
  <p>I also have defined a repository for my user model:</p>
  
  <pre><code>// UserRepo.java
  public interface UserRepo extends CassandraRepository&lt;User&gt; {
  }
  </code></pre>
  
  <p>Now I'm trying to test my repo class using the following simple test case:</p>
  
  <pre><code>// UserRepoTest.java
  @RunWith(SpringRunner.class)
  @AutoConfigureTestDatabase(replace = Replace.NONE)
  @DataJpaTest
  public class UserRepoTest {
  
    @Autowired
    private UserRepo userRepo = null;
  
    @Autowired
    private TestEntityManager entityManager = null;
  
    @Test
    public void findOne_whenUserExists_thenReturnUser() {
      String id = UUID.randomUUID().toString();
      User user = new User();
      user.setId(id);
      this.entityManager.persist(user);
  
      assertEquals(this.userRepo.findOne(user.getId()).getId(), id);
    }
  
    @Test
    public void findOne_whenUserNotExists_thenReturnNull() {
      assertNull(this.userRepo.findOne(UUID.randomUUID().toString()));
    }
  }
  </code></pre>
  
  <p>I would expect the test to pass, but instead, I got an error saying "No qualifying bean of type 'com.datastax.driver.core.Cluster' available". It looks like spring failed to autowire the <code>cluster</code> object, but why is that? How do I fix this? Thanks a lot!</p>