当前位置: 首页 > 知识库问答 >
问题:

Spring Boot不在application.properties中使用MongoDB uri

符畅
2023-03-14
server.port=8186

# MONGODB (MongoProperties)
#spring.data.mongodb.host=localhost
#spring.data.mongodb.port=27018 
#spring.data.mongodb.database=educharge

spring.data.mongodb.uri=mongodb://52.15.64.17:27017/educharge
spring.data.mongodb.database=educharge
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.6.RELEASE)

2017-09-16 03:10:08.402  INFO 9536 --- [  restartedMain] c.E.E.EduchargeApiApplication            : Starting EduchargeApiApplication on Sankar with PID 9536 (G:\EduchargeAPI\EduchargeAPI\bin started by R Dinesh Kumar in G:\EduchargeAPI\EduchargeAPI)
2017-09-16 03:10:08.402  INFO 9536 --- [  restartedMain] c.E.E.EduchargeApiApplication            : No active profile set, falling back to default profiles: default
2017-09-16 03:10:08.408  INFO 9536 --- [  restartedMain] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@53b63b22: startup date [Sat Sep 16 03:10:08 IST 2017]; root of context hierarchy
2017-09-16 03:10:09.716  INFO 9536 --- [  restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8186 (http)
2017-09-16 03:10:09.718  INFO 9536 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2017-09-16 03:10:09.718  INFO 9536 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.16
2017-09-16 03:10:09.750  INFO 9536 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-09-16 03:10:09.750  INFO 9536 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1342 ms
2017-09-16 03:10:09.816  INFO 9536 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2017-09-16 03:10:09.826  INFO 9536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'metricsFilter' to: [/*]
2017-09-16 03:10:09.827  INFO 9536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-09-16 03:10:09.827  INFO 9536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-09-16 03:10:09.827  INFO 9536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-09-16 03:10:09.827  INFO 9536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2017-09-16 03:10:09.827  INFO 9536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'webRequestLoggingFilter' to: [/*]
2017-09-16 03:10:09.827  INFO 9536 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'applicationContextIdFilter' to: [/*]
2017-09-16 03:10:09.866  INFO 9536 --- [  restartedMain] org.mongodb.driver.cluster               : Cluster created with settings {hosts=[127.0.0.1:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=50}
2017-09-16 03:10:10.071  INFO 9536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@53b63b22: startup date [Sat Sep 16 03:10:08 IST 2017]; root of context hierarchy
2017-09-16 03:10:10.088  INFO 9536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Posts/showPost/{postid}],methods=[GET]}" onto public com.Educharge.EduchargeAPI.Model.Post com.Educharge.EduchargeAPI.Controller.PostController.showPost(int)
2017-09-16 03:10:10.089  INFO 9536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Posts/{postid}/like/{userid}],methods=[GET]}" onto public com.Educharge.EduchargeAPI.Model.Post com.Educharge.EduchargeAPI.Controller.PostController.likePost(int,int)
2017-09-16 03:10:10.090  INFO 9536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Posts/editPost],methods=[PUT]}" onto public com.Educharge.EduchargeAPI.Model.Post com.Educharge.EduchargeAPI.Controller.PostController.editPost(com.Educharge.EduchargeAPI.Model.Post)
2017-09-16 03:10:10.090  INFO 9536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Posts/{postid}/comment/{userid}],methods=[PUT]}" onto public com.Educharge.EduchargeAPI.Model.Post com.Educharge.EduchargeAPI.Controller.PostController.commentPost(java.lang.String,int,int)
2017-09-16 03:10:10.090  INFO 9536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Posts/createPost],methods=[POST]}" onto public com.Educharge.EduchargeAPI.Model.Post com.Educharge.EduchargeAPI.Controller.PostController.createPost(com.Educharge.EduchargeAPI.Model.Post)
2017-09-16 03:10:10.090  INFO 9536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Posts/deletePost/{postid}],methods=[DELETE]}" onto public com.Educharge.EduchargeAPI.Model.Post com.Educharge.EduchargeAPI.Controller.PostController.deletePost(int)
2017-09-16 03:10:10.091  INFO 9536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Posts/{postid}/dislike/{userid}],methods=[GET]}" onto public com.Educharge.EduchargeAPI.Model.Post com.Educharge.EduchargeAPI.Controller.PostController.dislikePost(int,int)
2017-09-16 03:10:10.096  INFO 9536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Profiles/showProfile/{userid}],methods=[GET]}" onto public com.Educharge.EduchargeAPI.Model.Profile com.Educharge.EduchargeAPI.Controller.ProfileController.showProfile(int)
2017-09-16 03:10:10.097  INFO 9536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Profiles/createProfile],methods=[POST]}" onto public com.Educharge.EduchargeAPI.Model.Profile com.Educharge.EduchargeAPI.Controller.ProfileController.addProfile(com.Educharge.EduchargeAPI.Model.Profile)
2017-09-16 03:10:10.097  INFO 9536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Profiles/editProfile],methods=[PUT]}" onto public com.Educharge.EduchargeAPI.Model.Profile com.Educharge.EduchargeAPI.Controller.ProfileController.editProfile(com.Educharge.EduchargeAPI.Model.Profile)
2017-09-16 03:10:10.097  INFO 9536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/Profiles/deleteProfile/{userid}],methods=[DELETE]}" onto public com.Educharge.EduchargeAPI.Model.Profile com.Educharge.EduchargeAPI.Controller.ProfileController.deleteProfile(int)
2017-09-16 03:10:10.101  INFO 9536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-09-16 03:10:10.102  INFO 9536 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : 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-16 03:10:10.118  INFO 9536 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-09-16 03:10:10.118  INFO 9536 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-09-16 03:10:10.141  INFO 9536 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-09-16 03:10:10.319  INFO 9536 --- [  restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/info || /info.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.321  INFO 9536 --- [  restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/heapdump || /heapdump.json],methods=[GET],produces=[application/octet-stream]}" onto public void org.springframework.boot.actuate.endpoint.mvc.HeapdumpMvcEndpoint.invoke(boolean,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException,javax.servlet.ServletException
2017-09-16 03:10:10.322  INFO 9536 --- [  restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/mappings || /mappings.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.323  INFO 9536 --- [  restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/configprops || /configprops.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.324  INFO 9536 --- [  restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/metrics/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint.value(java.lang.String)
2017-09-16 03:10:10.324  INFO 9536 --- [  restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/metrics || /metrics.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.325  INFO 9536 --- [  restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/beans || /beans.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.325  INFO 9536 --- [  restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/dump || /dump.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.326  INFO 9536 --- [  restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/health || /health.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(javax.servlet.http.HttpServletRequest,java.security.Principal)
2017-09-16 03:10:10.329  INFO 9536 --- [  restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/auditevents || /auditevents.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.boot.actuate.endpoint.mvc.AuditEventsMvcEndpoint.findByPrincipalAndAfterAndType(java.lang.String,java.util.Date,java.lang.String)
2017-09-16 03:10:10.330  INFO 9536 --- [  restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint.value(java.lang.String)
2017-09-16 03:10:10.330  INFO 9536 --- [  restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env || /env.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.332  INFO 9536 --- [  restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/loggers/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint.get(java.lang.String)
2017-09-16 03:10:10.333  INFO 9536 --- [  restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/loggers/{name:.*}],methods=[POST],consumes=[application/vnd.spring-boot.actuator.v1+json || application/json],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint.set(java.lang.String,java.util.Map<java.lang.String, java.lang.String>)
2017-09-16 03:10:10.333  INFO 9536 --- [  restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/loggers || /loggers.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.334  INFO 9536 --- [  restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/trace || /trace.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.336  INFO 9536 --- [  restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/autoconfig || /autoconfig.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-09-16 03:10:10.367  INFO 9536 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2017-09-16 03:10:10.434  INFO 9536 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-09-16 03:10:10.443  INFO 9536 --- [  restartedMain] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
2017-09-16 03:10:10.499  INFO 9536 --- [  restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8186 (http)
2017-09-16 03:10:10.501  INFO 9536 --- [  restartedMain] c.E.E.EduchargeApiApplication            : Started EduchargeApiApplication in 2.166 seconds (JVM running for 4203.36)
2017-09-16 03:10:10.873  INFO 9536 --- [127.0.0.1:27017] org.mongodb.driver.cluster               : Exception in monitor thread while connecting to server 127.0.0.1:27017

com.mongodb.MongoSocketOpenException: Exception opening socket
    at com.mongodb.connection.SocketStream.open(SocketStream.java:63) ~[mongodb-driver-core-3.4.2.jar:na]
    at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115) ~[mongodb-driver-core-3.4.2.jar:na]
    at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113) ~[mongodb-driver-core-3.4.2.jar:na]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_144]
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:1.8.0_144]
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) ~[na:1.8.0_144]
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) ~[na:1.8.0_144]
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) ~[na:1.8.0_144]
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source) ~[na:1.8.0_144]
    at java.net.PlainSocketImpl.connect(Unknown Source) ~[na:1.8.0_144]
    at java.net.SocksSocketImpl.connect(Unknown Source) ~[na:1.8.0_144]
    at java.net.Socket.connect(Unknown Source) ~[na:1.8.0_144]
    at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:57) ~[mongodb-driver-core-3.4.2.jar:na]
    at com.mongodb.connection.SocketStream.open(SocketStream.java:58) ~[mongodb-driver-core-3.4.2.jar:na]
    ... 3 common frames omitted

并打印异常打开套接字

是否有其他方法连接远程MongoDB主机服务器?

共有1个答案

邵沛
2023-03-14

如果连接到远程Mongodb实例,是否检查了52.15.64.17is pingable?

基于连接到MongoDB数据库

spring.data.mongodb.uri=mongodb://user:secret@mongo1.example.com:12345,mongo2.example.com:23456/test

或者,您可以为MongoDB静音Springboot自动配置:

@SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
 类似资料:
  • 使用的技术: Spring Boot 1.4.2.Release,Spring 4.3.4.Release,Tymeleaf 2.1.5.Release,Tomcat Embeded 8.5.6、Maven 3、Java 8 我创建了这个服务来发送电子邮件

  • 我已经为Postgresql启用了复制,并且正在使用PGPool进行负载平衡。 我在使用HikariCP甚至Apache DBCP连接到Postgres时遇到了问题。 在SpringBoot应用程序中有没有使用PGPool的方法? 请查找堆栈跟踪: 2018-08-10 10:20:19.124信息37879----[main]com.zaxxer.hikari.hikaridatasource:

  • 我在这里有一个Spring Boot应用程序:https://github.com/christophstrobl/spring-data-solr-showcase/tree/4b3bbf945b182855003d5ba63a60990972a9de72 它可以编译并很好地使用: 但是,当我单击Spring Tools Suite中的“Run as Spring Boot App”时,我得到一

  • 我正在尝试将属性从pom.xml加载到application.properties中。我想创建两个配置文件:dev和prod来使用不同的数据库URL。我使用Jenkins作为CI,在我的所有应用程序中(主要是Spring MVC,没有引导项目)都使用maven配置文件部署到Tomcat。使用maven属性可以做到这一点吗?我尝试了这样的方法:

  • 问题内容: 我们正在开发一个Spring Boot Web应用程序,正在使用的数据库是MySql; 我们拥有的设置是我们首先在本地对其进行测试(意味着我们需要在PC上安装MySql); 然后我们推向Bitbucket ; Jenkins自动检测到对Bitbucket的新推送并在其上进行构建(要使Jenkins mvn构建通过,我们还需要在运行Jenkins的虚拟机上安装MySql)。 如果Jenk