无法通过Springboot连接到远程MongoDB

我试图连接到一个远程的MongoDB。 由于我没有得到一个MongoOpenSocketException,我认为已经建立了一个连接,但需要更多的启动应用程序。 我错过了什么?

Application.kt

package hello import org.springframework.boot.SpringApplication import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration import org.springframework.context.annotation.Configuration /** * The main entry point to the application */ @EnableAutoConfiguration(exclude = arrayOf(MongoAutoConfiguration::class)) @Configuration class Application /** * Run the application * @param args The command line arguments */ fun main(args: Array) { SpringApplication.run(Application::class.java, *args) } 

的build.gradle:

 // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext.kotlin_version = '1.1.2-4' repositories { mavenCentral() } dependencies { // Needed for the 'kotlin' plugin classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // Needed for the 'org.springframework.boot' plugin classpath "org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE" // Needed for the 'kotlin-spring' plugin classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version" } } // Allows us to compile Kotlin files apply plugin: 'kotlin' // Does some extra work to set up Spring Boot. // Specifically this gives us the "bootRun" task we will be using apply plugin: 'org.springframework.boot' // Allows for improved interop between Kotlin and Spring apply plugin: 'kotlin-spring' repositories { mavenCentral() } dependencies { // MongoDB compile "org.springframework.boot:spring-boot-starter-data-mongodb" // Kotlin Dependencies compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" // Spring Dependencies compile("org.springframework.boot:spring-boot-starter-web") { exclude module: "spring-boot-starter-tomcat" } compile "org.springframework.boot:spring-boot-starter-jetty" compile "org.springframework.boot:spring-boot-starter-actuator" // Jackson Dependencies compile "com.fasterxml.jackson.core:jackson-annotations" compile "com.fasterxml.jackson.core:jackson-core" compile "com.fasterxml.jackson.core:jackson-databind" runtime "com.fasterxml.jackson.datatype:jackson-datatype-jdk8" runtime "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" runtime "com.fasterxml.jackson.module:jackson-module-kotlin" } task wrapper(type: Wrapper) { gradleVersion = "3.5" } 

application.properties:

 spring.data.mongodb.host=asdf spring.data.mongodb.port=27017 spring.data.mongodb.database=asdf spring.data.mongodb.username=asdf spring.data.mongodb.password=asdf spring.data.mongodb.ssl.enabled=true 

主要错误:

 Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creatin g bean with name 'mongoDbFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mongoDbFactory' parameter 0; nested exception is org.springfr amework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.mongodb.MongoClient' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} 

堆栈跟踪:

 D:\Software Projects\Web Projects\spring-boot-kotlin-demo>gradlew bootRun > Task :compileKotlin Using kotlin incremental compilation > Task :findMainClass Using a single directory for all classes from a source set. This behaviour has been deprecated and is scheduled to be removed in Gradle 5.0 . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.5.2.RELEASE) 2017-09-18 16:49:27.329 INFO 3364 --- [ main] hello.ApplicationKt : Starting ApplicationKt on Martin with PID 3364 (started by Martin in D:\Software Projects\Web Projects\spring-boot-kotlin-demo) 2017-09-18 16:49:27.332 INFO 3364 --- [ main] hello.ApplicationKt : No active profile set, falling back to default profiles: default 2017-09-18 16:49:27.377 INFO 3364 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@11a9e7c8: startup date [Mon Sep 18 16:49:27 CEST 2017]; root o f context hierarchy 2017-09-18 16:49:28.421 INFO 3364 --- [ main] org.eclipse.jetty.util.log : Logging initialized @1730ms to org.eclipse.jetty.util.log.Slf4jLog 2017-09-18 16:49:28.669 INFO 3364 --- [ main] ejJettyEmbeddedServletContainerFactory : Server initialized with port: 8080 2017-09-18 16:49:28.670 INFO 3364 --- [ main] org.eclipse.jetty.server.Server : jetty-9.4.2.v20170220 2017-09-18 16:49:28.905 INFO 3364 --- [ main] org.eclipse.jetty.server.session : DefaultSessionIdManager workerName=node0 2017-09-18 16:49:28.905 INFO 3364 --- [ main] org.eclipse.jetty.server.session : No SessionScavenger set, using defaults 2017-09-18 16:49:28.907 INFO 3364 --- [ main] org.eclipse.jetty.server.session : Scavenging every 600000ms 2017-09-18 16:49:28.912 INFO 3364 --- [ main] oejetty.ContextHandler.application : Initializing Spring embedded WebApplicationContext 2017-09-18 16:49:28.912 INFO 3364 --- [ main] osweb.context.ContextLoader : Root WebApplicationContext: initialization completed in 1537 ms 2017-09-18 16:49:29.121 INFO 3364 --- [ main] osbwservlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2017-09-18 16:49:29.123 INFO 3364 --- [ main] osbwservlet.FilterRegistrationBean : Mapping filter: 'metricsFilter' to: [/*] 2017-09-18 16:49:29.123 INFO 3364 --- [ main] osbwservlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 2017-09-18 16:49:29.124 INFO 3364 --- [ main] osbwservlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2017-09-18 16:49:29.124 INFO 3364 --- [ main] osbwservlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 2017-09-18 16:49:29.124 INFO 3364 --- [ main] osbwservlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 2017-09-18 16:49:29.124 INFO 3364 --- [ main] osbwservlet.FilterRegistrationBean : Mapping filter: 'webRequestLoggingFilter' to: [/*] 2017-09-18 16:49:29.124 INFO 3364 --- [ main] osbwservlet.FilterRegistrationBean : Mapping filter: 'applicationContextIdFilter' to: [/*] 2017-09-18 16:49:29.313 INFO 3364 --- [ main] oejetty.server.handler.ContextHandler : Started osbcejJettyEmbeddedWebAppContext@1a35993f{/,[file:///C:/Users/Martin/AppData/Local/Temp/jetty-docbase.3939673008410127417.8080/],AVAILABLE} 2017-09-18 16:49:29.314 INFO 3364 --- [ main] org.eclipse.jetty.server.Server : Started @2624ms 2017-09-18 16:49:29.575 INFO 3364 --- [ main] swsmmaRequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@11a9e7c8: startup date [Mon Sep 18 16:49:2 7 CEST 2017]; root of context hierarchy 2017-09-18 16:49:29.639 INFO 3364 --- [ main] swsmmaRequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map> org.springframework.boot.autoconfigure .web.BasicErrorController.error(javax.servlet.http.HttpServletRequest) 2017-09-18 16:49:29.640 INFO 3364 --- [ main] swsmmaRequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController .errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 2017-09-18 16:49:29.672 INFO 3364 --- [ main] oswshandler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2017-09-18 16:49:29.672 INFO 3364 --- [ main] oswshandler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2017-09-18 16:49:29.707 INFO 3364 --- [ main] oswshandler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2017-09-18 16:49:29.770 WARN 3364 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creatin g bean with name 'mongoDbFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mongoDbFactory' parameter 0; nested exception is org.springfr amework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.mongodb.MongoClient' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} 2017-09-18 16:49:29.774 INFO 3364 --- [ main] org.eclipse.jetty.server.session : Stopped scavenging 2017-09-18 16:49:29.779 INFO 3364 --- [ main] oejetty.server.handler.ContextHandler : Stopped osbcejJettyEmbeddedWebAppContext@1a35993f{/,[file:///C:/Users/Martin/AppData/Local/Temp/jetty-docbase.3939673008410127417.8080/],UNAVAILABLE} 2017-09-18 16:49:29.787 INFO 3364 --- [ main] utoConfigurationReportLoggingInitializer : Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 2017-09-18 16:49:29.890 ERROR 3364 --- [ main] osbdLoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START