Spring Boot, Hibernate Search properties

£可爱£侵袭症+ 提交于 2019-12-11 09:04:24

问题


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


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/55801790/spring-boot-creating-hibernate-search-class-for-initial-lucene-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!