title: Spring Data Elasticsearch integration test using Testcontainers in SpringBoot
body: <p>I am trying out to write an integration test for Spring Data Elastisearch repository in SpringBoot using Testcontainers and junit5. But the test fails with</p>
  <blockquote>
  <p>org.springframework.beans.factory.UnsatisfiedDependencyException:
  Error creating bean with name
  'com.example.demo.AddressRepositoryTest': Unsatisfied dependency
  expressed through field 'repository'; nested exception is
  org.springframework.beans.factory.NoSuchBeanDefinitionException: No
  qualifying bean of type 'com.example.demo.AddressRepository'
  available: expected at least 1 bean which qualifies as autowire
  candidate. Dependency annotations:
  {@org.springframework.beans.factory.annotation.Autowired(required=true)}</p>
  </blockquote>
  <p>How could I fix this issue? I tried googling but could not find anything appropriate.</p>
  <p>DTO</p>
  <pre><code>@Data
  @Document(indexName = &quot;addresses&quot;)
  public class Address {
      String city;
      String street;
      GeoJsonPoint location;
  }
  </code></pre>
  <p>Repository</p>
  <pre><code>@Repository
  public interface AddressRepository extends ElasticsearchRepository&lt;Address, String&gt; {
  
  }
  </code></pre>
  <p>The test AddressRepositoryTest.java</p>
  <pre><code>@ExtendWith(SpringExtension.class)
  @Testcontainers
  class AddressRepositoryTest {
  
      private static final String ELASTICSEARCH_VERSION = &quot;7.10.1&quot;;
  
      static class Initializer implements ApplicationContextInitializer&lt;ConfigurableApplicationContext&gt; {
          @Override
          public void initialize(final ConfigurableApplicationContext configurableApplicationContext) {
  
          }
      }
  
      @Container
      public static ElasticsearchContainer container = new ElasticsearchContainer(DockerImageName
              .parse(&quot;docker.elastic.co/elasticsearch/elasticsearch-oss&quot;)
              .withTag(ELASTICSEARCH_VERSION));
  
      @Autowired
      AddressRepository repository;
  
      @Autowired
      private Config esConfig;
  
      @BeforeEach
      void setUp() {
          container.start();
          System.setProperty(&quot;elasticsearch.host&quot;, container.getContainerIpAddress());
          System.setProperty(&quot;elasticsearch.port&quot;, String.valueOf(container.getMappedPort(9300)));
          assertTrue(container.isRunning());
      }
  
      @AfterEach
      void tearDown() {
          container.stop();
      }
  
      @Test
      void save() {
          final Address address = new Address();
          address.setCity(&quot;Some city&quot;);
          address.setStreet(&quot;Some street&quot;);
  
          address.setLocation(GeoJsonPoint.of(0, 0));
          final Address save = repository.save(address);
  
      }
  }
  </code></pre>