com.github.ydespreaux.spring.data.elasticsearch.repository.config.EnableElasticsearchRepositories Maven / Gradle / Ivy
/*
* Copyright (C) 2018 Yoann Despréaux
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING . If not, write to the
* Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Please send bugreports with examples or suggestions to [email protected]
*/
package com.github.ydespreaux.spring.data.elasticsearch.repository.config;
import com.github.ydespreaux.spring.data.elasticsearch.core.ElasticsearchTemplate;
import com.github.ydespreaux.spring.data.elasticsearch.repository.support.ElasticsearchRepositoryFactoryBean;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Import;
import org.springframework.data.repository.config.DefaultRepositoryBaseClass;
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
import java.lang.annotation.*;
/**
* Annotation to enable Elasticsearch repositories. Will scan the package of the annotated configuration class for
* Spring Data repositories by default.
*
* @author Yoann Despréaux
* @since 1.0.0
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Import(ElasticsearchRepositoriesRegistrar.class)
public @interface EnableElasticsearchRepositories {
/**
* Alias for the {@link #basePackages()} attribute. Allows for more concise annotation declarations e.g.:
* {@code @EnableElasticsearchRepositories("org.my.pkg")} instead of
* {@code @EnableElasticsearchRepositories(basePackages="org.my.pkg")}.
*
* @return base packages
*/
String[] value() default {};
/**
* Base packages to scan for annotated components. {@link #value()} is an alias for (and mutually exclusive with) this
* attribute. Use {@link #basePackageClasses()} for a type-safe alternative to text-based package names.
*
* @return base packages
*/
String[] basePackages() default {};
/**
* Type-safe alternative to {@link #basePackages()} for specifying the packages to scan for annotated components. The
* package of each class specified will be scanned. Consider creating a special no-op marker class or interface in
* each package that serves no purpose other than being referenced by this attribute.
*
* @return base packages
*/
Class[] basePackageClasses() default {};
/**
* Specifies which types are eligible for component scanning. Further narrows the set of candidate components from
* everything in {@link #basePackages()} to everything in the base packages that matches the given filter or filters.
*
* @return include filters
*/
Filter[] includeFilters() default {};
/**
* Specifies which types are not eligible for component scanning.
*
* @return exclude filters
*/
Filter[] excludeFilters() default {};
/**
* Returns the postfix to be used when looking up custom repository implementations. Defaults to {@literal Impl}. So
* for a repository named {@code PersonRepository} the corresponding implementation class will be looked up scanning
* for {@code PersonRepositoryImpl}.
*
* @return repository implementation post prefix
*/
String repositoryImplementationPostfix() default "Impl";
/**
* Configures the location of where to find the Spring Data named queries properties file. Will default to
* {@code META-INFO/elasticsearch-named-queries.properties}.
*
* @return names queries location
*/
String namedQueriesLocation() default "";
/**
* Returns the key of the {@link org.springframework.data.repository.query.QueryLookupStrategy} to be used for lookup
* queries for query methods. Defaults to
* {@link org.springframework.data.repository.query.QueryLookupStrategy.Key#CREATE_IF_NOT_FOUND}.
*
* @return query lookup strategy
*/
Key queryLookupStrategy() default Key.CREATE_IF_NOT_FOUND;
/**
* Returns the {@link org.springframework.beans.factory.FactoryBean} class to be used for each repository instance.
* Defaults to {@link ElasticsearchRepositoryFactoryBean}.
*
* @return the repository factory bean class
*/
Class repositoryFactoryBeanClass() default ElasticsearchRepositoryFactoryBean.class;
/**
* Configure the repository base class to be used to create repository proxies for this particular configuration.
*
* @return base package
*/
Class repositoryBaseClass() default DefaultRepositoryBaseClass.class;
/**
* Configures the name of the {@link ElasticsearchTemplate} bean definition to be used to create repositories
* discovered through this annotation. Defaults to {@code elasticsearchTemplate}.
*
* @return bean name for elasticsearch template
*/
String elasticsearchTemplateRef() default "restElasticsearchTemplate";
}