|
For the latest stable version, please use Spring Data Meilisearch 0.12.0! |
Repository Configuration
Spring Data Meilisearch repositories are enabled through @EnableMeilisearchRepositories or the XML namespace.
Repository bootstrap registers interfaces against a MeilisearchOperations bean. It does not create the client, template, or converter for you, and this module does not provide Spring Boot auto-configuration. The default operations bean name is meilisearchTemplate; use meilisearchTemplateRef to select another bean. Repository creation can apply settings declared on the mapped entity; see Automatic Settings Application.
JavaConfig
import io.vanslog.spring.data.meilisearch.repository.config.EnableMeilisearchRepositories;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableMeilisearchRepositories(
basePackages = "com.example.movies",
meilisearchTemplateRef = "meilisearchTemplate")
class RepositoryConfig {
}
@EnableMeilisearchRepositories supports the standard Spring Data repository bootstrap options for scanning and
repository factory selection, including:
-
valueandbasePackages -
basePackageClasses -
includeFiltersandexcludeFilters -
repositoryImplementationPostfix -
repositoryFactoryBeanClass -
meilisearchTemplateRef -
considerNestedRepositories
If no base packages are configured, Spring Data scans the package of the annotated configuration class.
namedQueriesLocation and queryLookupStrategy are retained on the annotation because they are part of the standard
Spring Data repository configuration contract.
Changing those attributes does not enable repository query methods in Spring Data Meilisearch.
Derived finder methods, declared @Query methods, and named-query-backed methods are rejected during repository
bootstrap with a Meilisearch-specific message until repository query method support is implemented.
XML Namespace
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:meilisearch="http://www.vanslog.io/spring/data/meilisearch"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.vanslog.io/spring/data/meilisearch
http://www.vanslog.io/spring/data/meilisearch/spring-meilisearch-1.0.xsd">
<context:property-placeholder/>
<bean id="jsonHandler" class="com.meilisearch.sdk.json.GsonJsonHandler"/>
<meilisearch:meilisearch-client
id="meilisearchClient"
api-key="${MEILISEARCH_API_KEY}"
request-timeout="5000"
request-interval="50"/>
<bean id="meilisearchTemplate"
class="io.vanslog.spring.data.meilisearch.client.msc.MeilisearchTemplate">
<constructor-arg ref="meilisearchClient"/>
</bean>
<meilisearch:repositories
base-package="com.example.movies"
meilisearch-template-ref="meilisearchTemplate"/>
</beans>
The XML namespace extends the Spring Data repository namespace and adds the meilisearch-template-ref attribute.
See XML namespace reference for the full attribute list.
The one-argument MeilisearchTemplate constructor provides a default mapping converter and ObjectMapper. Wire them explicitly only when you need to customize conversion; see Object Mapping.