简体   繁体   English

spring boot不在application.properties中使用MongoDB uri

[英]spring boot not using the MongoDB uri in the application.properties

In my Spring-boot application , I was trying to use MongoDB which is in AWS instance . 在我的Spring-boot应用程序中 ,我试图使用AWS实例中的 MongoDB For that, I used the host and port number of the AWS Instance to connect it through Spring-boot 为此,我使用AWS Instance主机和端口号通过Spring-boot连接它

application.properties application.properties

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

when I run the application the program connect to localhost instead of host( 52.15.64.17) 当我运行应用程序时程序连接到localhost而不是主机(52.15.64.17)

Console output 控制台输出

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: 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

and prints the Exception opening socket 并打印异常打开套接字

Is there any other way to connect the remote MongoDB host server ? 有没有其他方法来连接远程MongoDB主机服务器?

If you are connecting to your remote Mongodb instance, have you checked 52.15.64.17 is pingable for you? 如果您要连接到远程Mongodb实例,请检查52.15.64.17是否可以ping通?

Based on Connecting to a MongoDB database : 基于连接到MongoDB数据库

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

Alternatively, You can mute the Springboot AutoConfiguration for mongoDB: 或者,您可以将mongoDB的Springboot自动配置静音:

@SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})

I had a similar problem using MongoDB and Embedded MongoDB, each one configured in a different spring profile. 我使用MongoDB和Embedded MongoDB遇到了类似的问题,每个问题都配置在不同的弹簧配置文件中。

In my case, the Spring was ignoring the MongoDB URI from my "production" profile and it always started the embedded mongoDb. 在我的例子中,Spring忽略了我的“生产”配置文件中的MongoDB URI,它总是启动嵌入式mongoDb。

The problem was the EmbeddedMongoAutoConfiguration enabled. 问题是启用了EmbeddedMongoAutoConfiguration So, you can disable the Embedded MongoDB in a specific profile using the properties: 因此,您可以使用以下属性在特定的配置文件中禁用Embedded MongoDB:

spring:
  autoconfigure:
    exclude: org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 引导应用程序不使用 Application.Properties 文件 - Spring Boot Application not using Application.Properties file Spring Boot 2:如何使用application.properties文件配置HikariCP - Spring Boot 2: How to configure HikariCP using application.properties file 在 Spring Boot 应用程序中使用 application.properties 进行组件扫描 - Component Scan using application.properties in spring boot app 属性值未使用 spring 引导从 application.properties 解析 - property value not resolved from application.properties using spring boot Spring 引导:尝试使用 EnvironmentPostProcessor 覆盖 application.properties - Spring Boot: Attempting to override application.properties using EnvironmentPostProcessor 使用 gradle 在 spring boot jar 中排除 application.properties - Exclude application.properties inside spring boot jar using gradle 使用application.properties文件激活配置文件以进行弹簧启动测试 - Activate profiles for spring boot test using application.properties file Spring Boot在application.properties中传递值/ using方法 - Spring Boot passing value / using method inside the application.properties Spring-Boot&gt;使用JNDI设置application.properties - Spring-Boot > Setting application.properties using JNDI 在 Spring Boot 的 application.properties 中使用 env 变量 - Using env variable in Spring Boot's application.properties
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM