我正在使用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读取我的配置文件的人?
将配置移动到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。
出于某种原因,只要hibernate.properties
配置文件不存在,hibernate-search就会阻止应用程序启动。在尝试了一段时间没有成功之后,我找到了解决问题的方法。
hibernate.properties
文件并将其放在src/main/resources
下。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所示。