spring - JHipster和mongodb : Error creating bean with name 'mongobee'

标签 spring mongodb maven spring-boot jhipster

我对 JHipster 相当陌生,我按照他们的说明创建了一个新应用程序。 该应用程序已创建,作为 Maven 项目导入到 STS 中,并且我更新了它。

但是,一旦我尝试通过启动仪表板启动它,我就会得到以下输出:

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,它成功了。

最佳答案

此错误意味着连接到您的数据库时出现错误,它在堆栈跟踪中确认了这一点:

Timed out after 30000 ms while waiting for a server

请仔细检查 src/main/resources/config/< 下的 application-dev.propertiesapplication-dev.yml 文件中的数据库配置.

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

YAML:

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>

关于spring - JHipster和mongodb : Error creating bean with name 'mongobee' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41021945/

相关文章:

java - 尝试访问 dao bean 时 Autowiring 依赖项的注入(inject)失败

java - 我有机会运行用户定义的程序来生成资源吗?

java - Spring 交易 : What will happen if I don't give @Transaction annotation on method

html - 将 css 类添加到输入标签 thymeleaf + spring

java - Spring如何调用Argumented Constructor

mongodb - 查找在指定日期之前创建的所有对象

node.js - 如何使用nodejs在mongodb内上传多个文件

mongodb - spring data - Mongodb - findBy 嵌套对象的方法

maven - Jenkins 插件显示在插件页面但不显示在配置页面

java - Karaf/Maven - 运行时找不到类