title: Spring Boot not autowiring class in test
body: <p>I have a Spring Boot 2 application with the following structure:</p>
  
  <pre><code>- src/main/java/com.mycompany/
  ---- application
  ---- domain
  ---- infrastructure
  -------- persistence
  ------------ ...
  -------- Application.java
  - src/main/test/java/com.mycompany/
  ---- application
  ---- domain
  ---- infrastructure
  -------- persistence
  ------------ testingutils
  ---------------- JdbcPersistenceHelper.java
  ------------ CurrenciesJdbcViewTest.java
  </code></pre>
  
  <p>Application class:</p>
  
  <pre><code>package com.mycompany.infrastructure;
  
  @SpringBootApplication
  public class Application {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  
  <p>JdbcPersistenceHelper:</p>
  
  <pre><code>package com.mycompany.infrastructure.persistence.testingutils;
  
  @Component
  public class JdbcPersistenceHelper {
  
      private EntityManager entityManager;
  
      @Autowired
      public JdbcPersistenceHelper(EntityManager entityManager) {
          this.entityManager = entityManager;
      }
  </code></pre>
  
  <p>CurrenciesJdbcViewTest:</p>
  
  <pre><code>package com.mycompany.infrastructure.persistence;
  
  @DataJpaTest
  public class CurrenciesJdbcViewTest {
  
      @Autowired
      private JdbcTemplate jdbcTemplate;
      @Autowired
      private JdbcPersistenceHelper persistenceHelper;
  
      private CurrenciesJdbcView view;
  
      @BeforeEach
      void setUp() {
          view = new CurrenciesJdbcView(jdbcTemplate);
      }
  </code></pre>
  
  <p>However, when I run the test, I got an error on ApplicationContext loading as follows:</p>
  
  <blockquote>
    <p>org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.mycompany.infrastructure.persistence.CurrenciesJdbcViewTest': Unsatisfied dependency expressed through field 'persistenceHelper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.mycompany.infrastructure.persistence.testingutils.JdbcPersistenceHelper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}</p>
  </blockquote>
  
  <p>It seems that spring is not detecting and autowiring <code>JdbcPersistenceHelper</code> class even though it is placed in a subpackage of <code>com.mycompany.infrastructure</code> where my spring boot's application class is located, so I think it should be able to detect it without any further configuration. 
  Am I missing something here?</p>