【问题标题】:JHipster and mongodb : Error creating bean with name 'mongobee'JHipster 和 mongodb:创建名称为“mongobee”的 bean 时出错
【发布时间】:2017-04-22 15:52:07
【问题描述】:

我对 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,它可以工作。

【问题讨论】:

    标签: spring mongodb maven spring-boot jhipster


    【解决方案1】:

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

    Timed out after 30000 ms while waiting for a server
    

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

    根据你是使用 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>
    

    【讨论】:

    • 我的 application-dev.yml 确实配置错误。谢谢你的回答。
    【解决方案2】:

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

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

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

    【讨论】:

      【解决方案3】:

      这能够解决我的问题:

      “回答了我自己的问题...从公共中删除 @Bean 定义 DatabaseConfiguration.java 中的 Mongobee mongobee(...) 似乎做了 诡计。尚未进行任何彻底的测试,但应用程序启动,我 可以创建新用户。”

      链接:https://github.com/jhipster/generator-jhipster/issues/8665

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-06-05
        • 2017-02-26
        • 2015-02-23
        • 1970-01-01
        • 2022-07-21
        • 2020-11-03
        • 1970-01-01
        相关资源
        最近更新 更多