org.hibernate.service.UnknownServiceException:请求了未知服务[org.hibernate.ogm.service.impl.OgmConfigurationService]

时间:2019-09-17 19:12:59

标签: java hibernate hibernate-ogm

我创建了一个使用MongoDB实现休眠OGM的应用程序。它在Eclipse中运行得很好,但是,当我构建一个胖的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编译了胖子。

这是我的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'   
}

1 个答案:

答案 0 :(得分:0)

此问题的解决方法是不再使用“胖罐”,而将依赖项保留在各自的罐中。 Jar合并会导致服务解析复杂化,从而产生UnknownServiceException