org.hibernate.service.UnknownServiceException:请求了未知服务 [org.hibernate.ogm.service.impl.OgmConfigurationService]
org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.ogm.service.impl.OgmConfigurationService]
我创建了一个使用 MongoDB 实现休眠 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)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:174)
at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:76)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:171)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:119)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:61)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:50)
at org.hibernate.ogm.jpa.HibernateOgmPersistence.createEntityManagerFactory(HibernateOgmPersistence.java:57)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at com.craftingdead.masterserver.player.PlayerManager.<init>(PlayerManager.java:76)
at com.craftingdead.masterserver.MasterServer.<init>(MasterServer.java:55)
at com.craftingdead.masterserver.MasterServer.main(MasterServer.java:70)
就我而言,我在类路径中拥有所有正确的依赖项。
我正在使用 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>
...还有我的 build.gradle
:
plugins {
id 'java-library'
id 'com.github.johnrengelman.shadow' version '5.1.0'
}
sourceCompatibility = targetCompatibility = 1.11
repositories {
jcenter()
maven {
name = 'jitpack'
url = 'https://jitpack.io'
}
maven {
name = 'minecraft'
url = 'https://libraries.minecraft.net'
}
}
sourceSets {
main {
java {
srcDir "network/src/main/java"
}
}
}
jar {
manifest {
attributes(
'Main-Class': 'com.craftingdead.masterserver.MasterServer',
'Multi-Release': 'true'
)
}
from {
configurations.required.collect { it.isDirectory() ? it : zipTree(it) }
}
}
shadowJar {
exclude "META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat"
}
configurations {
api.extendsFrom required
}
dependencies {
// Project Lombok
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.8'
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.8'
// Netty/All In One
required group: 'io.netty', name: 'netty-all', version: '4.1.36.Final'
// Guava: Google Core Libraries For Java
required group: 'com.google.guava', name: 'guava', version: '27.1-jre'
// Apache Log4j Core
required group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.2'
// Apache Log4j JUL Adapter
required group: 'org.apache.logging.log4j', name: 'log4j-jul', version: '2.11.2'
// Apache Log4j SLF4J Binding
required group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.11.2'
// Fastutil
required group: 'it.unimi.dsi', name: 'fastutil', version: '8.2.2'
// EventBus
required group: 'org.greenrobot', name: 'eventbus', version: '3.1.1'
// Brigadier
required group: 'com.mojang', name: 'brigadier', version: '1.0.17'
// Apache Commons Lang
required group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
// Authlib
required group: 'com.mojang', name: 'authlib', version: '1.5.25'
// SnakeYAML
required group: 'org.yaml', name: 'snakeyaml', version: '1.24'
// Hibernate OGM For MongoDB
required group: 'org.hibernate.ogm', name: 'hibernate-ogm-mongodb', version: '5.4.1.Final'
// JAXB API
required group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
// Hibernate Search ORM
required group: 'org.hibernate', name: 'hibernate-search-orm', version: '5.10.4.Final'
// Jackson Databind
required group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.10.0.pr1'
}
已通过不再使用 'fat jar' 并将依赖项保留在各自的 jar 中来解决此问题。 Jar 合并导致服务解析复杂化,从而产生 UnknownServiceException
.
我创建了一个使用 MongoDB 实现休眠 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)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:174)
at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:76)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:171)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:119)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:61)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:50)
at org.hibernate.ogm.jpa.HibernateOgmPersistence.createEntityManagerFactory(HibernateOgmPersistence.java:57)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at com.craftingdead.masterserver.player.PlayerManager.<init>(PlayerManager.java:76)
at com.craftingdead.masterserver.MasterServer.<init>(MasterServer.java:55)
at com.craftingdead.masterserver.MasterServer.main(MasterServer.java:70)
就我而言,我在类路径中拥有所有正确的依赖项。
我正在使用 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>
...还有我的 build.gradle
:
plugins {
id 'java-library'
id 'com.github.johnrengelman.shadow' version '5.1.0'
}
sourceCompatibility = targetCompatibility = 1.11
repositories {
jcenter()
maven {
name = 'jitpack'
url = 'https://jitpack.io'
}
maven {
name = 'minecraft'
url = 'https://libraries.minecraft.net'
}
}
sourceSets {
main {
java {
srcDir "network/src/main/java"
}
}
}
jar {
manifest {
attributes(
'Main-Class': 'com.craftingdead.masterserver.MasterServer',
'Multi-Release': 'true'
)
}
from {
configurations.required.collect { it.isDirectory() ? it : zipTree(it) }
}
}
shadowJar {
exclude "META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat"
}
configurations {
api.extendsFrom required
}
dependencies {
// Project Lombok
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.8'
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.8'
// Netty/All In One
required group: 'io.netty', name: 'netty-all', version: '4.1.36.Final'
// Guava: Google Core Libraries For Java
required group: 'com.google.guava', name: 'guava', version: '27.1-jre'
// Apache Log4j Core
required group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.2'
// Apache Log4j JUL Adapter
required group: 'org.apache.logging.log4j', name: 'log4j-jul', version: '2.11.2'
// Apache Log4j SLF4J Binding
required group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.11.2'
// Fastutil
required group: 'it.unimi.dsi', name: 'fastutil', version: '8.2.2'
// EventBus
required group: 'org.greenrobot', name: 'eventbus', version: '3.1.1'
// Brigadier
required group: 'com.mojang', name: 'brigadier', version: '1.0.17'
// Apache Commons Lang
required group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
// Authlib
required group: 'com.mojang', name: 'authlib', version: '1.5.25'
// SnakeYAML
required group: 'org.yaml', name: 'snakeyaml', version: '1.24'
// Hibernate OGM For MongoDB
required group: 'org.hibernate.ogm', name: 'hibernate-ogm-mongodb', version: '5.4.1.Final'
// JAXB API
required group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
// Hibernate Search ORM
required group: 'org.hibernate', name: 'hibernate-search-orm', version: '5.10.4.Final'
// Jackson Databind
required group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.10.0.pr1'
}
已通过不再使用 'fat jar' 并将依赖项保留在各自的 jar 中来解决此问题。 Jar 合并导致服务解析复杂化,从而产生 UnknownServiceException
.