1

spring boot 应用程序使用 mongobee 和 mongodb,spring 数据配置如下:

spring:
    data:
        mongodb:
            uri: mongodb://james:xxxxxxx@localhost:27017/?authSource=admin
            database: shortvideo

mongodb 是由另一个 docker 容器创建和启动的,当我使用 docker-compose 和 prod 配置文件启动应用程序时,总是出现以下错误:

hdshortvideo-app_1_5c3629434c46 | 2018-11-15 02:21:36.924  WARN 1 --- [           main] ConfigServletWebServerApplicationContext : 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/james/shortvideo/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is com.mongodb.MongoQueryException: Query failed with error code 13 and error message 'there are no users authenticated' on server hdshortvideo-mongodb:27017
hdshortvideo-app_1_5c3629434c46 | 2018-11-15 02:21:36.936  INFO 1 --- [           main] c.j.s.config.CacheConfiguration          : Closing Cache Manager
hdshortvideo-mongodb_1_753bbfb0d5aa | 2018-11-15T02:21:36.966+0000 I ACCESS   [conn3] Unauthorized: not authorized on admin to execute command { endSessions: [ { id: UUID("4083d867-552a-4882-8b21-fd1c2f0de0f7") } ], $db: "admin", $readPreference: { mode: "primaryPreferred" } }
hdshortvideo-mongodb_1_753bbfb0d5aa | 2018-11-15T02:21:36.973+0000 I NETWORK  [conn3] end connection 172.25.0.3:60404 (2 connections now open)
hdshortvideo-mongodb_1_753bbfb0d5aa | 2018-11-15T02:21:36.974+0000 I NETWORK  [conn2] end connection 172.25.0.3:60398 (1 connection now open)
hdshortvideo-app_1_5c3629434c46 | 2018-11-15 02:21:36.975  INFO 1 --- [           main] com.netflix.discovery.DiscoveryClient    : Shutting down DiscoveryClient ...
hdshortvideo-app_1_5c3629434c46 | 2018-11-15 02:21:36.987  WARN 1 --- [           main] .s.c.a.CommonAnnotationBeanPostProcessor : Invocation of destroy method failed on bean with name 'scopedTarget.eurekaClient': org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaInstanceConfigBean': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
hdshortvideo-app_1_5c3629434c46 | 2018-11-15 02:21:37.023 ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed
hdshortvideo-app_1_5c3629434c46 |
hdshortvideo-app_1_5c3629434c46 | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongobee' defined in class path resource [com/james/shortvideo/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is com.mongodb.MongoQueryException: Query failed with error code 13 and error message 'there are no users authenticated' on server hdshortvideo-mongodb:27017
hdshortvideo-app_1_5c3629434c46 |       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1699)
hdshortvideo-app_1_5c3629434c46 |       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573)
hdshortvideo-app_1_5c3629434c46 |       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)

当我用 shell 连接到 mongodb 时,我可以在那里找到用户“james”:

> show users
{
        "_id" : "admin.james",
        "user" : "james",
        "db" : "admin",
        "roles" : [
                {
                        "role" : "root",
                        "db" : "admin"
                }
        ]
}

那么“没有经过身份验证的用户”到底是什么意思?我搜索了很多但没有运气,我现在被卡住了。

4

0 回答 0