我創建了一個使用 MongoDB 實現 hibernate OGM 的應用程序。它在 Eclipse 中運行得很好,但是,當我構建一個 fat jar 并嘗試運行它時,出現以下錯誤:Exception in thread "main" org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.ogm.service.impl.OgmConfigurationService] at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) at org.hibernate.ogm.boot.impl.OgmMetadataBuilderInitializer.contribute(OgmMetadataBuilderInitializer.java:28) at org.hibernate.boot.internal.MetadataBuilderImpl.<init>(MetadataBuilderImpl.java:141) at org.hibernate.boot.MetadataSources.getMetadataBuilder(MetadataSources.java:136) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:218)就我而言,我在類路徑中擁有所有正確的依賴項。我使用 JDK 11 并使用https://github.com/johnrengelman/shadow編譯 fat jar 。這是我的persistence.xml:<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.2" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"> <persistence-unit name="crafting-dead-master-server"> <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider> <properties> <property name="hibernate.ogm.datastore.provider" value="MONGODB" /> <property name="hibernate.ogm.datastore.database" value="crafting-dead-master-server" /> <property name="hibernate.ogm.datastore.create_database" value="true" /> <property name="hibernate.search.default.directory_provider" value="filesystem" /> <property name="hibernate.search.default.indexBase" value="lucene/indexes" /> </properties> </persistence-unit></persistence>
1 回答

慕沐林林
TA貢獻2016條經驗 獲得超9個贊
通過不再使用“fat jar”并將依賴項保留在各自的 jar 中,解決了這個問題。Jar 合并導致服務解析變得復雜,從而產生了UnknownServiceException
.
添加回答
舉報
0/150
提交
取消