5
votes

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

2
Where are those properties?chrylis -cautiouslyoptimistic-
inside application properties file, at src/main/resources. Other jpa and datasource settings get evaluated fine.prageeth
Thanks @chrylis. I got it working.prageeth

2 Answers

24
votes

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.

3
votes

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