2017-03-28 4 views
2

ich diese Ausnahme erhalten:Ungültige Mongo Konfiguration, entweder uri oder Host/Port/Anmeldeinformationen angegeben werden muss

Caused by: java.lang.IllegalStateException: Invalid mongo configuration, either uri or host/port/credentials must be specified 
    at org.springframework.boot.autoconfigure.mongo.MongoProperties.createMongoClient(MongoProperties.java:207) 
    at org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration.mongo(MongoAutoConfiguration.java:73) 
    at org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration$$EnhancerBySpringCGLIB$$15f9b896.CGLIB$mongo$1(<generated>) 
    at org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration$$EnhancerBySpringCGLIB$$15f9b896$$FastClassBySpringCGLIB$$c0338f6a.invoke(<generated>) 
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) 
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) 
    at org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration$$EnhancerBySpringCGLIB$$15f9b896.mongo(<generated>) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) 
    ... 25 common frames omitted 

Hier ist mein application.yml Inhalt:

spring: 
    data: 
    mongodb: 
     uri: mongodb://develop:[email protected]<my_host>:27017/SHAM 

Hier ist mein Konfigurationsklasse:

Jetzt bekomme ich diese Stack-Trace beim Start ohne Fehler, es sieht aus wie Benutzer entwickeln hat nicht das Recht zu verbinden:

Caused by: com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server phelbwlabect003.karmalab.net:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" } 
    at com.mongodb.connection.CommandHelper.createCommandFailureException(CommandHelper.java:170) 
    at com.mongodb.connection.CommandHelper.receiveCommandResult(CommandHelper.java:123) 
    at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:32) 
    at com.mongodb.connection.SaslAuthenticator.sendSaslStart(SaslAuthenticator.java:117) 
    at com.mongodb.connection.SaslAuthenticator.access$000(SaslAuthenticator.java:37) 
    at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:50) 
    ... 9 common frames omitted 
+0

In meinem Fall war ein aktives Profil in der Datei 'application.properties' gesetzt. Dieses Profil hat die 'spring.data.mongodb.uri' festgelegt, während ich' spring.data.mongodb.host' usw. in 'application.properties' eingestellt habe. – rocksteady

Antwort

3

Sie mischen die URI-Stil Verbindungseinstellungen mit den einzelnen Eigenschaften Stileinstellungen.

Entweder verwenden

spring: 
    data: 
     mongodb: 
      host: localhost 
      port: 27017 
      database: SHAM_TEST 
      username: develop 
      password: pass 

Oder

spring: 
    data: 
     mongodb: 
      uri:mongodb://develop:[email protected]:27017/SHAM_TEST 
+0

Jetzt verwende ich nur das Uri-Format. – Sofiane

+0

Ich habe meine Frage bereits korrigiert. Und fügte einen weiteren hinzu. – Sofiane

+0

Sind Sie in der SHAM-Datenbank entwickelt? Ich sehe sowohl SHAM als auch SHAM_TEST in Ihrem Code. – Veeram

3

Die Frage war Authentisierungs-Datenbank fehlte.

Hier ist nun die Arbeitskonfiguration:

spring: 
    data: 
    mongodb: 
     host: <my_host> 
     username: develop 
     password: d3VeL0p$ 
     port: 27017 
     database: SHAM 
     repositories: 
     enabled: true 
     authentication-database: admin 
+0

Bitte markieren Sie diese Frage als gelöst. – halfer

0

Wenn Sie application.properties Datei verwenden, um die Konfiguration zu speichern, verwenden Sie die folgende Struktur.

spring.data.mongodb.host = localhost 
spring.data.mongodb.port = 27017 
spring.data.mongodb.database = SHAM_TEST 
spring.data.mongodb.username = develop 
spring.data.mongodb.password = pass 
Verwandte Themen