hibernate 当转换为JAR时,休眠搜索不起作用

ntjbwcob  于 2022-11-14  发布在  其他
关注(0)|答案(1)|浏览(95)

我有一个使用Hibernate Search的应用程序。我一直在本地开发它,在IntelliJ内部运行得很好。但是,当我将其导出到一个JAR文件并运行它时,我遇到了Hibernate搜索初始化的问题。
它给出了一个错误,即一个Bean对于属性“hibernate.earch.coheration.Strategy”的“None”不可用。休眠文档说这个属性是可选的。当我从IntelliJ运行我的代码时,这也不是问题。仅当我编译JAR并从命令行运行它时。
我正在使用:
Hibernate 6.1.3
休眠搜索6.1.7
Hibernate Search Mapper ORM ORM6 6.1.7
Hibernate搜索后端Lucene 6.1.7
如果有帮助的话,我会使用MAVEN作为依赖项。下面是我的完整pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <properties>
        <java.version>18</java.version>
    </properties>

    <groupId>groupId</groupId>
    <artifactId>KanjiBattleServer</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>18</source>
                    <target>18</target>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>18</source>
                    <target>18</target>
                    <compilerArguments>
                        <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
                    </compilerArguments>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>4.0.0</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.29</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>6.1.3.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-jpamodelgen</artifactId>
            <version>6.1.3.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate.search</groupId>
            <artifactId>hibernate-search-mapper-orm-orm6</artifactId>
            <version>6.1.7.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.search</groupId>
            <artifactId>hibernate-search-backend-lucene</artifactId>
            <version>6.1.7.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate.search</groupId>
            <artifactId>hibernate-search-mapper-orm-coordination-outbox-polling-orm6</artifactId>
            <version>6.1.7.Final</version>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.6</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>5.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-scratchpad</artifactId>
            <version>5.0.0</version>
        </dependency>

        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>4.2.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
            <version>4.1.53.Final</version>
        </dependency>

    </dependencies>

</project>

我不确定这是我如何构建JAR的问题,还是什么问题,因为其他依赖项似乎做得很好(比如Netty)。
以下是完整错误:

java.lang.ExceptionInInitializerError
        at com.company.Utils.AdminServerConnections.getUserFromDB(AdminServerConnections.java:73)   
        at com.company.Utils.AdminServerConnections.getUser(AdminServerConnections.java:38)
        at com.company.ConnectionResponse.processAdminCommand(ConnectionResponse.java:93)
        at com.company.AdminConnectionHandler.channelRead(AdminConnectionHandler.java:68)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerCont
ext.java:357)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:302)   
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerCont
ext.java:357)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:1
03)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerCont
ext.java:357)
        at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.ja
va:93)
        at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.
java:82)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerCont
ext.java:357)
        at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandshakeHandler.channelRea
d(WebSocketServerProtocolHandshakeHandler.java:65)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerCont
ext.java:357)
        at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerCont
ext.java:357)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:1
03)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerCont
ext.java:357)
        at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannel
Read(CombinedChannelDuplexHandler.java:436)
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324
)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)   
        at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.ja
va:251)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:365)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerCont
ext.java:357)
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.ja
va:1410)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:379)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo
ntext.java:365)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) 
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.jav
a:166)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)    
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:9
89)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)    
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.hibernate.search.util.common.SearchException: HSEARCH000501: Invalid value for config
uration property 'hibernate.search.coordination.strategy': ''. HSEARCH000579: Unable to resolve bean
 reference to type 'org.hibernate.search.mapper.orm.coordination.common.spi.CoordinationStrategy' an
d name 'none'. Failed to resolve bean from Hibernate Search's internal registry with exception: HSEA
RCH000578: No beans defined for type 'org.hibernate.search.mapper.orm.coordination.common.spi.Coordi
nationStrategy' and name 'none' in Hibernate Search's internal registry. Failed to resolve bean from
 bean manager with exception: HSEARCH000590: No configured bean manager. Failed to resolve bean from
 bean manager with exception: HSEARCH000591: Unable to resolve 'none' to a class extending 'org.hibe
rnate.search.mapper.orm.coordination.common.spi.CoordinationStrategy': HSEARCH000530: Unable to load
 class 'none': Could not load requested class : none Failed to resolve bean using reflection with ex
ception: HSEARCH000591: Unable to resolve 'none' to a class extending 'org.hibernate.search.mapper.o
rm.coordination.common.spi.CoordinationStrategy': HSEARCH000530: Unable to load class 'none': Could 
not load requested class : none
        at org.hibernate.search.engine.cfg.impl.AbstractConfigurationProperty.doGet(AbstractConfigur
ationProperty.java:61)
        at org.hibernate.search.engine.cfg.impl.AbstractConfigurationProperty.getAndTransform(Abstra
ctConfigurationProperty.java:36)
        at org.hibernate.search.mapper.orm.coordination.impl.CoordinationConfigurationContextImpl.co
nfigure(CoordinationConfigurationContextImpl.java:38)
        at org.hibernate.search.mapper.orm.bootstrap.impl.HibernateSearchPreIntegrationService.coord
inationStrategyConfiguration(HibernateSearchPreIntegrationService.java:193)
        at org.hibernate.search.mapper.orm.bootstrap.impl.HibernateSearchCompositeMappingProducer.pr
oduceAdditionalMappings(HibernateSearchCompositeMappingProducer.java:50)
        at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingPro
cess.java:329)
        at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProces
s.java:97)
        at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:402)      
        at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:90)       
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:735)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:773)
        at com.company.UtilDatabase.<clinit>(UtilDatabase.java:18)
        ... 52 more
Caused by: org.hibernate.search.engine.environment.bean.spi.BeanNotFoundException: HSEARCH000579: Un
able to resolve bean reference to type 'org.hibernate.search.mapper.orm.coordination.common.spi.Coor
dinationStrategy' and name 'none'. Failed to resolve bean from Hibernate Search's internal registry 
with exception: HSEARCH000578: No beans defined for type 'org.hibernate.search.mapper.orm.coordinati
on.common.spi.CoordinationStrategy' and name 'none' in Hibernate Search's internal registry. Failed 
to resolve bean from bean manager with exception: HSEARCH000590: No configured bean manager. Failed 
to resolve bean from bean manager with exception: HSEARCH000591: Unable to resolve 'none' to a class
 extending 'org.hibernate.search.mapper.orm.coordination.common.spi.CoordinationStrategy': HSEARCH00
0530: Unable to load class 'none': Could not load requested class : none Failed to resolve bean usin
g reflection with exception: HSEARCH000591: Unable to resolve 'none' to a class extending 'org.hiber
nate.search.mapper.orm.coordination.common.spi.CoordinationStrategy': HSEARCH000530: Unable to load 
class 'none': Could not load requested class : none
        at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.resolveFromFirstSucces
sfulSource(BeanResolverImpl.java:173)
        at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.resolve(BeanResolverIm
pl.java:91)
        at org.hibernate.search.engine.environment.bean.TypeAndNameBeanReference.resolve(TypeAndName
BeanReference.java:28)
        at org.hibernate.search.engine.environment.bean.BeanResolver.resolve(BeanResolver.java:75)  
        at org.hibernate.search.engine.cfg.impl.DefaultedConfigurationProperty.convert(DefaultedConf
igurationProperty.java:27)
        at org.hibernate.search.engine.cfg.impl.AbstractConfigurationProperty.doGet(AbstractConfigur
ationProperty.java:44)
        ... 63 more
        Suppressed: org.hibernate.search.engine.environment.bean.spi.BeanNotFoundException: HSEARCH0
00590: No configured bean manager.
                at org.hibernate.search.engine.environment.bean.impl.NoConfiguredBeanManagerBeanProv
ider.forTypeAndName(NoConfiguredBeanManagerBeanProvider.java:37)
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.tryResolve(Bea
nResolverImpl.java:196)
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.resolveFromFir
stSuccessfulSource(BeanResolverImpl.java:162)
                ... 68 more
        Suppressed: org.hibernate.search.engine.environment.bean.spi.BeanNotFoundException: HSEARCH0
00591: Unable to resolve 'none' to a class extending 'org.hibernate.search.mapper.orm.coordination.c
ommon.spi.CoordinationStrategy': HSEARCH000530: Unable to load class 'none': Could not load requeste
d class : none
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.toClass(BeanRe
solverImpl.java:211)
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.tryResolve(Bea
nResolverImpl.java:198)
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.resolveFromFir
stSuccessfulSource(BeanResolverImpl.java:162)
                ... 68 more
        Caused by: org.hibernate.search.engine.environment.classpath.spi.ClassLoadingException: HSEA
RCH000530: Unable to load class 'none': Could not load requested class : none
                at org.hibernate.search.engine.environment.classpath.spi.DefaultClassResolver.classF
orName(DefaultClassResolver.java:39)
                at org.hibernate.search.mapper.orm.bootstrap.impl.HibernateOrmClassLoaderServiceClas
sAndResourceAndServiceResolver.classForName(HibernateOrmClassLoaderServiceClassAndResourceAndService
Resolver.java:60)
                at org.hibernate.search.engine.environment.classpath.spi.ClassLoaderHelper.classForN
ame(ClassLoaderHelper.java:174)
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.toClass(BeanRe
solverImpl.java:208)
                ... 70 more
        Caused by: java.lang.ClassNotFoundException: Could not load requested class : none
                at org.hibernate.search.engine.environment.classpath.spi.AggregatedClassLoader.findC
lass(AggregatedClassLoader.java:108)
                at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
                at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
                at java.base/java.lang.Class.forName0(Native Method)
                at java.base/java.lang.Class.forName(Class.java:488)
                at java.base/java.lang.Class.forName(Class.java:467)
                at org.hibernate.search.engine.environment.classpath.spi.DefaultClassResolver.classF
orName(DefaultClassResolver.java:36)
                ... 73 more
        Suppressed: org.hibernate.search.engine.environment.bean.spi.BeanNotFoundException: HSEARCH0
00591: Unable to resolve 'none' to a class extending 'org.hibernate.search.mapper.orm.coordination.c
ommon.spi.CoordinationStrategy': HSEARCH000530: Unable to load class 'none': Could not load requeste
d class : none
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.toClass(BeanRe
solverImpl.java:211)
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.tryResolve(Bea
nResolverImpl.java:200)
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.resolveFromFir
stSuccessfulSource(BeanResolverImpl.java:162)
                ... 68 more
        Caused by: org.hibernate.search.engine.environment.classpath.spi.ClassLoadingException: HSEA
RCH000530: Unable to load class 'none': Could not load requested class : none
                at org.hibernate.search.engine.environment.classpath.spi.DefaultClassResolver.classF
orName(DefaultClassResolver.java:39)
                at org.hibernate.search.mapper.orm.bootstrap.impl.HibernateOrmClassLoaderServiceClas
sAndResourceAndServiceResolver.classForName(HibernateOrmClassLoaderServiceClassAndResourceAndService
Resolver.java:60)
                at org.hibernate.search.engine.environment.classpath.spi.ClassLoaderHelper.classForN
ame(ClassLoaderHelper.java:174)
                at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.toClass(BeanRe
solverImpl.java:208)
                ... 70 more
        Caused by: java.lang.ClassNotFoundException: Could not load requested class : none
                at org.hibernate.search.engine.environment.classpath.spi.AggregatedClassLoader.findC
lass(AggregatedClassLoader.java:108)
                at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
                at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
                at java.base/java.lang.Class.forName0(Native Method)
                at java.base/java.lang.Class.forName(Class.java:488)
                at java.base/java.lang.Class.forName(Class.java:467)
                at org.hibernate.search.engine.environment.classpath.spi.DefaultClassResolver.classF
orName(DefaultClassResolver.java:36)
                ... 73 more
Caused by: org.hibernate.search.engine.environment.bean.spi.BeanNotFoundException: HSEARCH000578: No
 beans defined for type 'org.hibernate.search.mapper.orm.coordination.common.spi.CoordinationStrateg
y' and name 'none' in Hibernate Search's internal registry.
        at org.hibernate.search.engine.environment.bean.impl.ConfigurationBeanRegistry.resolve(Confi
gurationBeanRegistry.java:53)
        at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.tryResolve(BeanResolve
rImpl.java:194)
        at org.hibernate.search.engine.environment.bean.impl.BeanResolverImpl.resolveFromFirstSucces
sfulSource(BeanResolverImpl.java:162)
        ... 68 more
uqxowvwt

uqxowvwt1#

在休眠论坛上被问到,并找到了答案。问题是IntelliJ在构建Jar时没有正确地打包东西。修复方法是打开JAR并添加行:org.hibernate.search.mapper.orm.impl.HibernateOrmBeanConfigurer
到位于META-INF/services/org.hibernate.search.engine.environment.bean.spi.BeanConfigurer的文件
在一条新线路上。所以编辑后的文件是这样的:

org.hibernate.search.engine.impl.EngineBeanConfigurer
org.hibernate.search.mapper.orm.impl.HibernateOrmBeanConfigurer

然后,JAR将通过Hibernate Search正确执行

相关问题