Spring Boot, Hibernate Search properties
Asked Answered
L

2

5

How to provide Hibernate Search parameters when using Spring Boot?

...
spring.datasource.driverClassName=org.postgresql.Driver

hibernate.search.jmx_enabled=true
hibernate.search.default.directory_provider=filesystem
hibernate.search.generate_statistics=true
hibernate.search.lucene_version=LUCENE_CURRENT
hibernate.search.default.indexBase=/mypath-to-index

It does not care what I provide. Default settings always get applied.

I think below code does not have anything to process properties related to Hibernate Search. Can that be the issue?

https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java

Lillie answered 24/8, 2014 at 17:36 Comment(2)
Where are those properties?Benignant
inside application properties file, at src/main/resources. Other jpa and datasource settings get evaluated fine.Lillie
J
26

You can put them in the application.properties file if you put "spring.jpa.properties." in front of the property names.

Example:

spring.jpa.properties.hibernate.search.jmx_enabled=true
spring.jpa.properties.hibernate.search.default.directory_provider=filesystem
spring.jpa.properties.hibernate.search.generate_statistics=true
spring.jpa.properties.hibernate.search.lucene_version=LUCENE_CURRENT
spring.jpa.properties.hibernate.search.default.indexBase=/mypath-to-index

Spring will take any properties under spring.jpa.properties.* and pass them along (with the prefix stripped) once the EntityManagerFactory is created.

Jaramillo answered 21/10, 2014 at 20:53 Comment(1)
Great! This is the cleanest solution and it is more in the way of Spring Data JPA (see here).Mares
L
3

Got it working.

Put another property file named "hibernate.properties" inside src/main/resources with below content.

hibernate.search.jmx_enabled=true
hibernate.search.default.directory_provider=filesystem
hibernate.search.generate_statistics=true
hibernate.search.lucene_version=LUCENE_CURRENT
hibernate.search.default.indexBase=/mypath-to-index
Lillie answered 24/8, 2014 at 17:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.