JHipster和mongodb:创建名为'mongobee'的bean时出错

问题描述 投票:1回答:2

我对JHipster很新,我按照他们的指示创建了一个新的应用程序。该应用程序已创建,作为Maven项目导入STS,我对其进行了更新。

但是,一旦我尝试通过Boot Dashboard启动它,我得到这个输出:

2016-12-07 16:43:14.887  INFO 6396 --- [  restartedMain] com.mycompany.myapp.MdcApp               : Starting MdcApp on PC981 with PID 6396 (C:\Users\lvuillaume\Desktop\mdc\target\classes started by lvuillaume in C:\Users\lvuillaume\Desktop\mdc)
2016-12-07 16:43:14.890 DEBUG 6396 --- [  restartedMain] com.mycompany.myapp.MdcApp               : Running with Spring Boot v1.4.2.RELEASE, Spring v4.3.4.RELEASE
2016-12-07 16:43:14.891  INFO 6396 --- [  restartedMain] com.mycompany.myapp.MdcApp               : The following profiles are active: swagger,dev
2016-12-07 16:43:14.972 DEBUG 6396 --- [kground-preinit] org.jboss.logging                        : Logging Provider: org.jboss.logging.Slf4jLoggerProvider found via system property
2016-12-07 16:43:18.499 DEBUG 6396 --- [  restartedMain] c.m.myapp.config.AsyncConfiguration      : Creating Async Task Executor
2016-12-07 16:43:19.041 DEBUG 6396 --- [  restartedMain] c.m.myapp.config.MetricsConfiguration    : Registering JVM gauges
2016-12-07 16:43:19.059 DEBUG 6396 --- [  restartedMain] c.m.myapp.config.MetricsConfiguration    : Initializing Metrics JMX reporting
2016-12-07 16:43:19.960  WARN 6396 --- [  restartedMain] io.undertow.websockets.jsr               : UT026009: XNIO worker was not set on WebSocketDeploymentInfo, the default worker will be used
2016-12-07 16:43:19.961  WARN 6396 --- [  restartedMain] io.undertow.websockets.jsr               : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2016-12-07 16:43:20.436  INFO 6396 --- [  restartedMain] c.mycompany.myapp.config.WebConfigurer   : Web application configuration, using profiles: [swagger, dev]
2016-12-07 16:43:20.437 DEBUG 6396 --- [  restartedMain] c.mycompany.myapp.config.WebConfigurer   : Initializing Metrics registries
2016-12-07 16:43:20.442 DEBUG 6396 --- [  restartedMain] c.mycompany.myapp.config.WebConfigurer   : Registering Metrics Filter
2016-12-07 16:43:20.442 DEBUG 6396 --- [  restartedMain] c.mycompany.myapp.config.WebConfigurer   : Registering Metrics Servlet
2016-12-07 16:43:20.445  INFO 6396 --- [  restartedMain] c.mycompany.myapp.config.WebConfigurer   : Web application fully configured
2016-12-07 16:43:20.491  INFO 6396 --- [  restartedMain] com.mycompany.myapp.MdcApp               : Running with Spring profile(s) : [swagger, dev]
2016-12-07 16:43:20.579 DEBUG 6396 --- [  restartedMain] c.m.myapp.config.CacheConfiguration      : No cache
2016-12-07 16:43:24.805 DEBUG 6396 --- [  restartedMain] c.m.m.c.apidoc.SwaggerConfiguration      : Starting Swagger
2016-12-07 16:43:24.816 DEBUG 6396 --- [  restartedMain] c.m.m.c.apidoc.SwaggerConfiguration      : Started Swagger in 10 ms
2016-12-07 16:43:24.849 DEBUG 6396 --- [  restartedMain] c.m.myapp.config.DatabaseConfiguration   : Configuring Mongobee
2016-12-07 16:43:24.854  INFO 6396 --- [  restartedMain] com.github.mongobee.Mongobee             : Mongobee has started the data migration sequence..
2016-12-07 16:43:54.876  WARN 6396 --- [  restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongobee' defined in class path resource [com/mycompany/myapp/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]
2016-12-07 16:43:54.883  INFO 6396 --- [  restartedMain] c.m.myapp.config.CacheConfiguration      : Closing Cache Manager
2016-12-07 16:43:54.905 ERROR 6396 --- [  restartedMain] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongobee' defined in class path resource [com/mycompany/myapp/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:754)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at com.mycompany.myapp.MdcApp.main(MdcApp.java:64)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]
    at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:369)
    at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:101)
    at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:75)
    at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:71)
    at com.mongodb.binding.ClusterBinding.getReadConnectionSource(ClusterBinding.java:63)
    at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:210)
    at com.mongodb.operation.FindOperation.execute(FindOperation.java:482)
    at com.mongodb.operation.FindOperation.execute(FindOperation.java:79)
    at com.mongodb.Mongo.execute(Mongo.java:772)
    at com.mongodb.Mongo$2.execute(Mongo.java:759)
    at com.mongodb.DBCollection.findOne(DBCollection.java:777)
    at com.mongodb.DBCollection.findOne(DBCollection.java:747)
    at com.mongodb.DBCollection.findOne(DBCollection.java:694)
    at com.github.mongobee.dao.ChangeEntryIndexDao.findRequiredChangeAndAuthorIndex(ChangeEntryIndexDao.java:26)
    at com.github.mongobee.dao.ChangeEntryDao.ensureChangeLogCollectionIndex(ChangeEntryDao.java:75)
    at com.github.mongobee.dao.ChangeEntryDao.connectMongoDb(ChangeEntryDao.java:34)
    at com.github.mongobee.Mongobee.execute(Mongobee.java:135)
    at com.github.mongobee.Mongobee.afterPropertiesSet(Mongobee.java:117)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579)
    ... 19 common frames omitted

我试图创建一个类似的项目,但没有Mongodb,它工作。

spring mongodb maven spring-boot jhipster
2个回答
3
投票

此错误表示连接到您的数据库时出错,它在您的堆栈跟踪中确认:

Timed out after 30000 ms while waiting for a server

请在application-dev.properties下的application-dev.ymlsrc/main/resources/config/文件中仔细检查您的数据库配置。

根据您是使用YAML还是JSON作为属性定义文件,请仔细检查数据库配置:

Yamla:

spring:
    data:
        mongodb:
            host: <your_host_address>
            port: <your_port>
            database: <database_name>

JSON:

spring.data.mongodb.host=<your_host_address>
spring.data.mongodb.port=<your_port>
spring.data.mongodb.database=<database_name>

0
投票

用MongoDb创建一个新的JHipster项目后,我遇到了同样的错误。

在运行mvnw之前(在Windows上)我忘了运行MongoDb本身。

所以在新的命令提示符下运行mongod.exe,然后运行mvnw为我解决了这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.