I developed a Spring boot application with MongoDB. While the MongoDB in the localhost, it works fine, but when the MongoDB is in different the server, I changed the setting in application.properties as
spring.data.mongodb.uri=mongodb://192.168.7.31/gcp
spring.data.mongodb.username=xxx
spring.data.mongodb.password=xxxxxxx
the application faileds as it still looks for the mongoDB in localhost
2017-01-04 11:47:46.161 INFO 15610 --- [ main] org.mongodb.driver.cluster : Adding discovered server localhost:27017 to client view of cluster
2017-01-04 11:47:46.218 INFO 15610 --- [localhost:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server localhost:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.SocketStream.open(SocketStream.java:63) ~[mongodb-driver-core-3.2.2.jar:na]
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114) ~[mongodb-driver-core-3.2.2.jar:na]
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorR
Anyone can help to tell me how to set the parameters?
Related
How can we start a spring boot application in IntelliJ community edition. I don't see an embedded tomcat Included here. When I start the application from SpringBootApplication annotated class, getting the below messages only in the logger
2021-06-23 20:02:45.933 INFO 1086 --- [ main] r.e.r.RestapplicationApplication : Starting RestapplicationApplication using Java 11.0.11 on Antonys-MBP.home with PID 1086 (/Users/robin/Documents/work/workspace/restapplication/target/classes started by robin in /Users/robin/Documents/work/workspace/restapplication)
2021-06-23 20:02:45.938 INFO 1086 --- [ main] r.e.r.RestapplicationApplication : No active profile set, falling back to default profiles: default
2021-06-23 20:02:48.342 INFO 1086 --- [ main] r.e.r.RestapplicationApplication : Started RestapplicationApplication in 3.621 seconds (JVM running for 4.888)
Please help on how can I start the application in tomcat and test in Community Editon of IntelliJ
r.e.r.RestapplicationApplication : Started RestapplicationApplication
in 3.621 seconds (JVM running for 4.888)
The above line tells you that the embedded tomcat has already started at default port 8080 ( unless you have overridden port in configuration). You can try hitting the application on the port.
I am using default docker image of MongoDB and trying to connect using simple spring Boot application on windows box.
mongoDB image is getting stared correctly
IP in mongoDB image
I have spring-boot-starter-data-mongodb in my class path. i am using all spring boot default and only using below property in application.properties.
spring.data.mongodb.host=192.168.99.100
On application startup getting Connection refused: connect error
Logs
019-03-06 06:15:06.096 INFO 4664 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[192.168.99.100:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2019-03-06 06:15:06.096 INFO 4664 --- [ main] org.mongodb.driver.cluster : Adding discovered server 192.168.99.100:27017 to client view of cluster
2019-03-06 06:15:06.356 WARN 4664 --- [ main] o.s.d.m.c.m.BasicMongoPersistentProperty : Customizing field name for id property not allowed! Custom name will not be considered!
2019-03-06 06:15:06.928 INFO 4664 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-03-06 06:15:07.164 INFO 4664 --- [68.99.100:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server 192.168.99.100:27017
What i am missing here ?
Not a MongoDB expert, but a moderate Docker user speaking: It looks like you are not publishing the port MongoDB runs by default: 27017. That's why your spring application could not get a connection and throws this exception:
Exception in monitor thread while connecting to server 192.168.99.100:27017
So you may try publishing the port by using -p 27017:27017when initiating mongo container.
I ran in a weird situation I never had before.
I've got a spring boot application running on intelliJ on ubuntu 18.
My spring boot application runs in a dev environment connected to a h2 in memory database. I have a session based login with spring security.
The weird thing is if after I stopped and restarted the application I am still logged in. And even if I completely restart IntelliJ the session is not cleared. Even the database keeps its state and is not getting dropped.
Only if I restart the whole system everything will be cleared.
Inside my application.properties there are no special properties set.
Everything's on default.
If I stop the application the following console output comes up:
2018-12-22 11:11:19.385 INFO 10000 --- [ Thread-35] ConfigServletWebServerApplicationContext : Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#73abcbfa: startup date [Sat Dec 22 11:11:00 CET 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#12e6f48a
2018-12-22 11:11:19.391 INFO 10000 --- [ Thread-35] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2018-12-22 11:11:19.391 INFO 10000 --- [ Thread-35] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans
2018-12-22 11:11:19.395 INFO 10000 --- [ Thread-35] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2018-12-22 11:11:19.395 INFO 10000 --- [ Thread-35] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed drop of schema as part of SessionFactory shut-down'
2018-12-22 11:11:19.415 WARN 10000 --- [ Thread-35] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLException:Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-197]
2018-12-22 11:11:19.417 INFO 10000 --- [ Thread-35] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2018-12-22 11:11:19.419 INFO 10000 --- [ Thread-35] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
Process finished with exit code 130 (interrupted by signal 2: SIGINT)
https://github.com/spring-projects/spring-boot/wiki/spring-boot-1.3.0-m3-release-notes
Update Tomcat, Jetty and Undertow to serialize session data when the
application is stopped and load it again when the application
restarts. Persistent session are opt-in; either by setting
persistentSession on the ConfigurableEmbeddedServletContainer or by
using the property server.session.persistent=true (Persistent sessions
are enabled by default with Devtools).
In spring boot 2, the property is:
server.servlet.session.persistent=false # Whether to persist session data between restarts.
I suppose you are talking about web login via browser (or REST-client). Also I suppose you're using default web security settings.
Then your login request creates a cookie with session id which is returned to browser and is being used in next requests until you close browser.
I have a Spring Boot application which runs on a remote server. When I build it to work over HTTP everything works fine. But when I am trying to setup SSL the application not work. It doesn't throw errors or anything. But I can't access any page in the browser (I have tried https://www.example.com, https://www.example.com:8443, https://example.com etc).
I have built keystore.jks on remote server machine from certificate.crt (which I have bought for my domain on ssl).
I have the following application.properties:
server.port=8443
server.ssl.key-store=classpath:keystore.jks
server.ssl.key-store-password=PASSWORD
server.ssl.key-password=PASSWORD
I have tried different configurations but no results. The same story happens when I trying to run it on my local machine (I thought it is because of I am going to localhost when the certificate is for example.com but maybe it is the same problem).
Here is the server output:
INFO 11041 --- [ main] o.e.jetty.util.ssl.SslContextFactory : x509=X509#2a492f2a(jetty,h=[www.example.com, example.com],w=[]) for >SslContextFactory#3277e499(jar:file:/root/application.jar!/BOOT->INF/classes!/keystore.jks,null)
2018-05-13 13:21:56.175 INFO 11041 --- [ main] >o.e.jetty.server.AbstractConnector : Started >ServerConnector#7ac2e39b{SSL,[ssl, http/1.1]}{0.0.0.0:8443}
2018-05-13 13:21:56.176 INFO 11041 --- [ main] >.s.b.c.e.j.JettyEmbeddedServletContainer : Jetty started on port(s) 8443 (ssl, http/1.1)
2018-05-13 13:21:56.179 INFO 11041 --- [ main] >c.b.product.BootApplication : Started BootApplication in 4.786 seconds (JVM running for 5.151)
So everything seems to be fine but it doesn't work.
Problem solved. It was just wrong generated keystore.jks.
I'm using spring cloud Brixton.M4 and spring boot is v1.3.1, with eureka first approach and application starts on random port server.port=0 but its register it self at port 0 with eureka server.
here is my bootstrap.properties file
server.port=0
spring.application.name=course-composite-service
spring.cloud.config.fail-fast=true
spring.cloud.config.label=config-dev
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.serviceId=config-server
eureka.client.serviceUrl.defaultZone=http://localhost:8002/eureka/
and below its the log
2016-01-11 18:36:50.286 INFO 17233 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_COURSE-COMPOSITE-SERVICE/192.168.17.178:course-composite-service:0: registering service...
2016-01-11 18:36:50.288 INFO 17233 --- [ main] .w.c.c.CourseCompositeServiceApplication : Started CourseCompositeServiceApplication in 5.325 seconds (JVM running for 5.856)
2016-01-11 18:36:50.321 INFO 17233 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_COURSE-COMPOSITE-SERVICE/192.168.17.178:course-composite-service:0 - registration status: 204
and eureka dashboard shows
COURSE-COMPOSITE-SERVICE UP (1) - 192.168.17.178:course-composite-service:0
why its not registering with the actual port its running?
i'm providing other eureka configurations from the Config Sever they are
eureka.client.register-with-eureka=true
eureka.instance.leaseRenewalIntervalInSeconds=10
eureka.instance.leaseExpirationDurationInSeconds=5
eureka.instance.preferIpAddress=false
eureka.instance.metadataMap.hostname=${vcap.application.application_uris[0]}
eureka.instance.metadataMap.instanceId=${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}}