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.
queryLookupStrategy defaults to CREATE_IF_NOT_FOUND and supports the derived finder subset documented in
Query Methods. USE_DECLARED_QUERY cannot resolve
derived methods. namedQueriesLocation remains available for Spring Data configuration compatibility, but named
queries and declared @Query methods are rejected at repository bootstrap.
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.