Tomcat服务器在启动时(HIbernate OGM,Mongodb,Spring Boot)忽略加载persistence.xml

时间:2018-07-18 06:00:58

标签: mongodb spring-boot tomcat8 hibernate-ogm

我的eclipse中运行的Spring Boot应用程序运行良好,该Eclipse配置了休眠ogm和mongodb。

当我尝试在外部tomcat中部署此项目war文件时,它显示以下错误。

  

2018年7月26日18:28:16.155严重[localhost-startStop-1] org.apache.catalina.core.StandardContext.listenerStart异常将上下文初始化事件发送到类[com.dmp.config.DBConfigContextListener ]    org.hibernate.service.spi.ServiceException:OGM000071:无法启动数据存储提供程序       在org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider.start(MongoDBDatastoreProvider.java:121)       在org.hibernate.service.internal.AbstractServiceRegistryImpl.startService(AbstractServiceRegistryImpl.java:339)       在org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:245)       在org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)       在org.hibernate.ogm.dialect.impl.GridDialectInitiator.initiateService(GridDialectInitiator.java:52)       在org.hibernate.ogm.dialect.impl.GridDialectInitiator.initiateService(GridDialectInitiator.java:36)       在org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)       在org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259)       在org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233)       在org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)       在org.hibernate.ogm.dialect.impl.OgmDialectFactoryInitiator $ OgmDialectFactory。(OgmDialectFactoryInitiator.java:44)       在org.hibernate.ogm.dialect.impl.OgmDialectFactoryInitiator.initiateService(OgmDialectFactoryInitiator.java:31)       在org.hibernate.ogm.dialect.impl.OgmDialectFactoryInitiator.initiateService(OgmDialectFactoryInitiator.java:25)       在org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)       在org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259)       在org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233)       在org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)       在org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:50)       在org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)       在org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)       在org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259)       在org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233)       在org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)       在org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)       在org.hibernate.ogm.service.impl.OgmJdbcServicesInitiator $ OgmJdbcServicesImpl.configure(OgmJdbcServicesInitiator.java:51)       在org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)       在org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242)       在org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)       在org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)       在org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)       在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:861)       在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:888)       在org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)       在org.hibernate.ogm.jpa.HibernateOgmPersistence.createEntityManagerFactory(HibernateOgmPersistence.java:57)       在javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)       在javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)       在com.dmp.config.DBConfigContextListener.contextInitialized(DBConfigContextListener.java:15)       在org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4751)       在org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5215)       在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)       在org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)       在org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)       在org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)       在org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:986)       在org.apache.catalina.startup.HostConfig $ DeployWar.run(HostConfig.java:1857)       在java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511)       在java.util.concurrent.FutureTask.run(FutureTask.java:266)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)       在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624)       在java.lang.Thread.run(Thread.java:748)   由以下原因引起:org.hibernate.HibernateException:OGM001214:无法连接到MongoDB实例:命令失败,错误13:服务器本地主机:27017上“没有经过身份验证的用户”。完整的响应为{“ ok”:0.0,“ errmsg”:“没有经过身份验证的用户”,“ code”:13,13,“ codeName”:“未经授权”}       在org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider.extractDatabase(MongoDBDatastoreProvider.java:186)       在org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider.start(MongoDBDatastoreProvider.java:116)       ...还有49个   由以下原因引起:com.mongodb.MongoCommandException:命令失败,错误13:服务器localhost:27017上“没有经过身份验证的用户”。完整的响应为{“ ok”:0.0,“ errmsg”:“没有经过身份验证的用户”,“ code”:13,13,“ codeName”:“未经授权”}       在com.mongodb.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:164)       在com.mongodb.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:295)       在com.mongodb.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:255)       在com.mongodb.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:98)       在com.mongodb.connection.DefaultConnectionPool $ PooledConnection.sendAndReceive(DefaultConnectionPool.java:441)       在com.mongodb.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:80)       在com.mongodb.connection.DefaultServer $ DefaultServerProtocolExecutor.execute(DefaultServer.java:189)       在com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:264)       在com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:126)       在com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:118)       在com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:226)       在com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:217)       在com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:120)       在com.mongodb.operation.ListCollectionsOperation $ 1.call(ListCollectionsOperation.java:178)       在com.mongodb.operation.ListCollectionsOperation $ 1.call(ListCollectionsOperation.java:173)       在com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:471)       在com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:415)       在com.mongodb.operation.ListCollectionsOperation.execute(ListCollectionsOperation.java:173)       在com.mongodb.operation.ListCollectionsOperation.execute(ListCollectionsOperation.java:81)       在com.mongodb.Mongo $ 3.execute(Mongo.java:826)       在com.mongodb.MongoIterableImpl.execute(MongoIterableImpl.java:130)       在com.mongodb.MongoIterableImpl.iterator(MongoIterableImpl.java:77)       在com.mongodb.MappingIterable.iterator(MappingIterable.java:40)       在org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider.extractDatabase(MongoDBDatastoreProvider.java:172)       ...另外50个

2018年7月26日18:28:16.158 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log关闭Spring根WebApplicationContext 26-Jul-2018 18:28:16.166严重[localhost-startStop-1] org.apache.catalina.core.StandardContext.listenerStop异常将上下文破坏事件发送到类[com.dmp.config.DBConfigContextListener]  java.lang.NullPointerException     在com.dmp.config.DBConfigContextListener.contextDestroyed(DBConfigContextListener.java:20)     在org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4798)     在org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5437)     在org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:226)     在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)     在org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)     在org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)     在org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)     在org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:986)     在org.apache.catalina.startup.HostConfig $ DeployWar.run(HostConfig.java:1857)     在java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511)     在java.util.concurrent.FutureTask.run(FutureTask.java:266)     在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)     在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624)     在java.lang.Thread.run(Thread.java:748)

我的 persistence.xml

<persistence-unit name="dmp" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>

    <properties>
        <property name="hibernate.ogm.datastore.provider" value="mongodb" />
        <property name="hibernate.ogm.datastore.database" value="dmp_test" />
        <property name="hibernate.ogm.datastore.host" value="localhost" />
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.ogm.mongodb.port" value="27017" />
        <!-- <property name="hibernate.search.default.directory_provider" value="filesystem"/>
        <property name="hibernate.search.default.indexBase" value="/tmp/.hibernate_ogm_demo_luceneindexes"/> -->
    </properties>
</persistence-unit>

pom.xml

<groupId>com.dmp</groupId>
<artifactId>dmp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>dmp</name>
<description>Top RTB DMP Process</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<!-- https://mvnrepository.com/artifact/org.hibernate.ogm/hibernate-ogm-bom -->
<!-- <dependencyManagement> <dependencies> <dependency> <groupId>org.hibernate.ogm</groupId> 
    <artifactId>hibernate-ogm-bom</artifactId> <version>5.3.1.Final</version> 
    <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> -->


<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hibernate.ogm</groupId>
        <artifactId>hibernate-ogm-core</artifactId>
        <version>5.3.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.ogm</groupId>
        <artifactId>hibernate-ogm-mongodb</artifactId>
        <version>5.3.1.Final</version>
        <!-- <scope>provided</scope> -->
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.3.1.Final</version><!--$NO-MVN-MAN-VER$ -->
        <exclusions>
            <exclusion>
                <groupId>org.hibernate.javax.persistence</groupId>
                <artifactId>hibernate-jpa-2.1-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.jboss.spec.javax.transaction</groupId>
                <artifactId>jboss-transaction-api_1.2_spec</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.4.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-search-orm</artifactId>
        <version>5.9.0.Final</version><!--$NO-MVN-MAN-VER$ -->
    </dependency>
    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>
        <version>1.0.2</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>
    <!-- maxmind geo ip dependencies -->
    <dependency>
        <groupId>com.maxmind.geoip</groupId>
        <artifactId>geoip-api</artifactId>
        <version>1.2.10</version>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20180130</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.9.5</version><!--$NO-MVN-MAN-VER$ -->
        <exclusions>
            <exclusion>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-annotations</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.9.5</version><!--$NO-MVN-MAN-VER$ -->
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.9.5</version><!--$NO-MVN-MAN-VER$ -->
    </dependency>
    <!-- standard APIs dependencies - provided in a Java EE container -->
    <!-- <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.1-api</artifactId> 
        </dependency> -->
    <!-- <dependency> <groupId>org.jboss.spec.javax.transaction</groupId> <artifactId>jboss-transaction-api_1.2_spec</artifactId> 
        </dependency> -->
    <!-- Add the Narayana Transactions Manager an implementation would be provided 
        in a Java EE container, but this works nicely in Java SE as well -->
    <!-- <dependency> <groupId>org.jboss.narayana.jta</groupId> <artifactId>narayana-jta</artifactId> 
        <version>5.8.1.Final</version>$NO-MVN-MAN-VER$ <scope>test</scope> </dependency> 
        <dependency> <groupId>org.jboss.jbossts.arjunacore</groupId> <artifactId>arjuna</artifactId> 
        <version>4.17.4.Final</version> </dependency> -->       <!-- <dependency> <groupId>org.jboss</groupId> <artifactId>jboss-transaction-spi</artifactId> 
        </dependency> -->
    <!-- <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> 
        <version>1.10.2.RELEASE</version>$NO-MVN-MAN-VER$ </dependency> -->
    <dependency>
        <groupId>com.scientiamobile.wurfl</groupId>
        <artifactId>wurfl</artifactId>
        <version>1.9.4.0</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>
    <dependency>
        <groupId>eu.bitwalker</groupId>
        <artifactId>UserAgentUtils</artifactId>
        <version>1.21</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.jbossts</groupId>
        <artifactId>jbossjta</artifactId>
        <version>4.16.4.Final</version>
        <scope>test</scope>
    </dependency>
</dependencies>
<repositories>
    <repository>
        <id>com.scientiamobile.wurfl</id>
        <name>com.scientiamobile.wurfl</name>
        <url>https://maven.scientiamobile.com/repository/wurfl-onsite/</url>
    </repository>
</repositories>
<build>
    <finalName>dmp</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <jvmArguments>
                    -Xdebug
                    -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9898
                </jvmArguments>
            </configuration>
        </plugin>
    </plugins>
</build>

DBConfigContextListner.java

public class DBConfigContextListener implements ServletContextListener {

private static EntityManagerFactory emf;

@Override
public void contextInitialized(ServletContextEvent event) {
    emf = Persistence.createEntityManagerFactory("dmp");
}

@Override
public void contextDestroyed(ServletContextEvent event) {
    emf.close();
}

public static EntityManager createEntityManager() {
    if (emf == null) {
        throw new IllegalStateException("Context is not initialized yet.");
    }
    return emf.createEntityManager();
}

}

SpringTestApplication.java

@SpringBootApplication

公共类SpringTestApplication {

@Bean
public ServletListenerRegistrationBean<ServletContextListener> listenerRegistrationBean() {
    ServletListenerRegistrationBean<ServletContextListener> bean = new ServletListenerRegistrationBean<>();
    bean.setListener(new DBConfigContextListener());
    return bean;

}

public static void main(String[] args) {
    SpringApplication.run(SpringTestApplication.class, args);
}

}

application.properties

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

还告诉我,application.properties中的上述属性是否为强制性的。

据我了解,提供程序未在服务器启动时加载。但我不知道如何使其手动加载。

如果有人知道如何解决,请帮助解决此问题。

建议,不胜感激。

谢谢 Jeevitha T

0 个答案:

没有答案