a spring boot application uses mongobee and mongodb, the spring data config is as below:
spring:
data:
mongodb:
uri: mongodb://james:xxxxxxx@localhost:27017/?authSource=admin
database: shortvideo
the mongodb is created and started by another docker container, when I start the application with docker-compose and prod profile, there are always below error:
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)
When I connect to the mongodb with shell, I can find the user "james" there:
> show users
{
"_id" : "admin.james",
"user" : "james",
"db" : "admin",
"roles" : [
{
"role" : "root",
"db" : "admin"
}
]
}
So what on earth does "there are no users authenticated mean? I googled a lot but no luck, I am stuck now.