如何在没有 persistence.xml 文件自动配置 Spring 引导应用程序的情况下禁用 Wildfly 10 Hibernate 搜索模块?

How to disable Wildfly 10 Hibernate Search module without persistence.xml file is autoconfigured Spring Boot app?

大家好!

我正在使用 Hibernate Search 5.5 开发 Spring Boot 1.5 应用程序。作为独立应用程序,它如我所料 运行,但我在 Wildfly 10 上部署它时遇到问题。在部署期间它抛出异常:java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: Provider org.hibernate.search.hcore.impl.HibernateSearchIntegrator not a subtype

我想禁用 Wildfly Hibernate Search 实现并提供我自己的应用程序预打包。 我发现我必须在 persistence.xml 文件中提供 wildfly.jpa.hibernate.search.module = none 属性。我的问题是如何在不重写整个 Spring 引导数据源自动配置的情况下做到这一点?

尝试将此添加到您的 application.yaml:

spring.jpa.properties:
    wildfly.jpa.hibernate.search.module: none

查看 Spring 使用 Hibernate Search here 启动应用程序的示例。 不过,它不使用 WildFly。

最后我找到了强制 Wildfly 不加载提供的 Hibernate Search 模块的解决方案。我已阅读第 Class Loading in Wildfly 章中有关提供 jboss-deployment-structure.xml 文件的 Wildfly 10 文档。在使用我的应用构建 WAR 文件期间,我将此文件添加到 META-INF 目录中,内容如下:

<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
    <deployment>
        <exclusions>
            <module name="org.hibernate.search.orm"/>
        </exclusions>
    </deployment>
</jboss-deployment-structure>

此配置解决了我的问题,Wildfly 正在加载与我的应用程序打包在一起的 Hibernate Search。