Hibernate Search的外部化配置

问题描述 投票:0回答:2

我正在使用spring boot运行hibernate搜索。我已经为我的应用程序编写了一个工作配置。但是,我想要外化我的配置并使用./config/hibernate.properties而不是src/main/resources/hibernate.properties。将我的属性文件复制到所需的位置后,我得到并且异常:

nested exception is java.io.FileNotFoundException: class path resource [hibernate.properties] cannot be opened because it does not exist

任何有任何想法我应该告诉spring读取我的配置文件的人?

spring-boot elasticsearch hibernate-search
2个回答
0
投票

将配置移动到src/main/resources/application.properties文件并在任何地方添加spring.jpa.properties.,例如hibernate.dialect将成为spring.jpa.properties.hibernate.dialect

然后,您可以使用Spring功能在任何地方移动配置。要将它移动到./config/application.properties,我想你必须将@PropertySource("./config/application.properties")添加到你的一个@Configuration类或类似的东西。

我相信你也可以将hibernate配置保存在一个单独的文件中(与其他应用程序配置分开)。

有关在Spring Boot中外部化配置的更多详细信息,请参阅https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html


0
投票

出于某种原因,只要hibernate.properties配置文件不存在,hibernate-search就会阻止应用程序启动。在尝试了一段时间没有成功之后,我找到了解决问题的方法。

  • 首先,我创建了一个空的hibernate.properties文件并将其放在src/main/resources下。
  • 其次,我将所有hibernate-search配置移动到application.properties,如下所示: spring.jpa.properties.hibernate.search.default.indexmanager = elasticsearch spring.jpa.properties.hibernate.search.default.elasticsearch.host = http://my-server.com spring.jpa.properties.hibernate.search.default.elasticsearch.index_schema_management_strategy = CREATE spring.jpa.properties.hibernate.search.default.elasticsearch.required_index_status = yellow

这样,应用程序将启动,spring将从外部化配置获得所有配置,如here所示。

© www.soinside.com 2019 - 2024. All rights reserved.