diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/config/ElasticsearchRepositoryConfigExtension.java b/src/main/java/org/springframework/data/elasticsearch/repository/config/ElasticsearchRepositoryConfigExtension.java index 741f3feb9..04afdd539 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/config/ElasticsearchRepositoryConfigExtension.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/config/ElasticsearchRepositoryConfigExtension.java @@ -15,8 +15,16 @@ */ package org.springframework.data.elasticsearch.repository.config; +import java.lang.annotation.Annotation; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.core.annotation.AnnotationAttributes; +import org.springframework.data.elasticsearch.annotations.Document; +import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; import org.springframework.data.elasticsearch.repository.support.ElasticsearchRepositoryFactoryBean; import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource; import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport; @@ -72,4 +80,22 @@ public class ElasticsearchRepositoryConfigExtension extends RepositoryConfigurat Element element = config.getElement(); builder.addPropertyReference("elasticsearchOperations", element.getAttribute("elasticsearch-template-ref")); } + + /* + * (non-Javadoc) + * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getIdentifyingAnnotations() + */ + @Override + protected Collection> getIdentifyingAnnotations() { + return Collections.>singleton(Document.class); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getIdentifyingTypes() + */ + @Override + protected Collection> getIdentifyingTypes() { + return Arrays.>asList(ElasticsearchRepository.class, ElasticsearchCrudRepository.class); + } } diff --git a/src/test/java/org/springframework/data/elasticsearch/config/EnableElasticsearchRepositoriesTests.java b/src/test/java/org/springframework/data/elasticsearch/config/EnableElasticsearchRepositoriesTests.java index b0442c256..e7101f08a 100644 --- a/src/test/java/org/springframework/data/elasticsearch/config/EnableElasticsearchRepositoriesTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/config/EnableElasticsearchRepositoriesTests.java @@ -21,12 +21,16 @@ import static org.junit.Assert.*; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.elasticsearch.core.ElasticsearchOperations; import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; import org.springframework.data.elasticsearch.repositories.sample.SampleElasticsearchRepository; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -37,7 +41,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration -public class EnableElasticsearchRepositoriesTests { +public class EnableElasticsearchRepositoriesTests implements ApplicationContextAware { + + ApplicationContext context; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.context = applicationContext; + } @Configuration @EnableElasticsearchRepositories(basePackages = "org.springframework.data.elasticsearch.repositories.sample") @@ -56,4 +67,16 @@ public class EnableElasticsearchRepositoriesTests { public void bootstrapsRepository() { assertThat(repository, is(notNullValue())); } + + @Test + public void shouldScanSelectedPackage() { + //given + + //when + String[] beanNamesForType = context.getBeanNamesForType(ElasticsearchRepository.class); + + //then + assertThat(beanNamesForType.length, is(1)); + assertThat(beanNamesForType[0], is("sampleElasticsearchRepository")); + } }