Spring boot actuator trying to make DB connection - spring-boot

I have a spring boot application written using jhipster that was handed to our project not long ago. It's been running under WebLogic and I'm in the process of moving it to Tomcat9, getting ready for cloud migration. I found that when I access actuator's "health", the application returned {"status" : "DOWN"} and it was attempting to connect to the database.
I don't want it to attempt the connection. I tried looking through the application but found no setting that seems to be causing this. I'm sure it's there somewhere, though.
Does anyone have any idea where I should look?
The following exception was thrown:
2020-04-13 07:41:32.003 ERROR 16156 --- [nio-8080-exec-9] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:743)
at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:666)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:566)
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:732)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:664)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:479)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:154)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118)
.
.
.

DB health check is enabled when you add actuator framework.
You can disable the db health check with this property:
management.health.db.enabled=false
Read more about all the actuator properties here:
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#actuator-properties

Related

Connecting remote kafka connection from localhost Spring boot applicaiton

My SpringBoot app is running on localhost, but I want it to connect with Kafka that is downloaded on remote server e.g. 123.45.6.789.
I am able to produce and consume messages from the mobaxTerm terminal but my springboot app is not able to connect with kafka due to this error
WARN[0;39m [35m18788[0;39m [2m---[0;39m [2m[ntainer#0-0-C-1][0;39m
[36morg.apache.kafka.clients.NetworkClient [0;39m [2m:[0;39m [Consumer
clientId=consumer-fooss-1, groupId=fooss] Connection to node -1
(localhost/127.0.0.1:9092) could not be established.
Broker may not be available.
my application.properties file
kafka.bootstrapAddress=123.45.6.789:9092
kafka.groupId=fooss
kafka.topicName=topicMyTopic
server.properties file
broker.id=0
listeners=PLAINTEXT://123.45.6.789:9092
advertised.listeners=PLAINTEXT://123.45.6.789:9092
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=123.45.6.789:2181
zookeeper.connection.timeout.ms=18000
I know that there are other questions related to this, and i have read them but i could not find answer to my problem... so please help me in understanding this...
my question is,
Why am i getting an error that says the connection was failed on localhost, even though i am trying to connect to 123.45.6.789 as mentioned in application.properties file?
and how can I resolve it?
Spring boot defaults to using localhost:9092, and it's unclear how you're using kafka.bootstrapAddress in your code.
The correct property for automatic configuration is spring.kafka.bootstrap-servers
https://docs.spring.io/spring-boot/docs/current/reference/html/messaging.html#messaging.kafka

Elasticsearch 7.10.2 doesn't bind application.properties variables on Mac M1

I'm facing a weird issue. I have 2 laptops, one running under Windows where everything works fine and on the other side, a Mac Mini M1.
Assuming, I'm developing a basic Spring Boot application with Elasticsearch as Repository.
In the application.yml, as usual I have the following properties :
spring:
elasticsearch:
rest:
uris: https://dummy-cloud-provider.cloud.com:12833
username: myusername
password: mypassword
But everytime I want to start the application on my Mac, I have the following error :
2021-06-23 15:55:51.972 ERROR [reactor-http-nio-3] r.c.p.Operators - Operator called default onErrorDropped
reactor.core.Exceptions$ErrorCallbackNotImplemented: org.springframework.data.elasticsearch.client.NoReachableHostException: Host 'localhost:9200' not reachable. Cluster state is offline.
Caused by: org.springframework.data.elasticsearch.client.NoReachableHostException: Host 'localhost:9200' not reachable. Cluster state is offline.
at org.springframework.data.elasticsearch.client.reactive.SingleNodeHostProvider.lambda$lookupActiveHost$3(SingleNodeHostProvider.java:101)
at reactor.core.publisher.FluxHandle$HandleSubscriber.onNext(FluxHandle.java:102)
at reactor.core.publisher.FluxMap$MapConditionalSubscriber.onNext(FluxMap.java:220)
at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java:79)
at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:2397)
...
I don't understand why it always skip my application.yml variables and try to reach localhost:9200.
I hope someone can help me :)
Best regards
This is not a Spring Data Elasticsearch problem, but a Spring Boot problem. Spring Data Elasticsearch does not use application properties to set anything up.
Looking at the configuration it seems that you want to set up a imperative (non-reactive) client connection to Elasticsearch?
The stacktrace shows that the failing call is done by the reactive client.
I suspect that you have the reactive Spring libraries (webflux) in the classpath and Spring boot actuator. And Spring Boot then configures a reactive client for the actuator using the default of localhost:9200.
I can't tell for sure without seeing your maven/gradle setup, but this for me is most possible explanation for this error.

Spring mongo driver connection pool close error

I have spring webflux/reactive server utilizing a singleton mongo database instance running on the same machine. Now, I have an rest endpoint in the server which triggers an external etl(python script using pymongo connection) on the db. But it then leads to pool close error on my spring server, and any subsequent database operations from the server fails.
2020-02-16T01:25:58.320+0530 [QUIET] [system.out] 2020-02-16 01:25:58.321 INFO 93553 --- [extShutdownHook] org.mongodb.driver.connection : Closed connection [connectionId{localValue:3, serverValue:133}] to localhost:27017 because the pool has been closed.
My etl runs for 10 secs, but mongo driver never reconnects after connection is closed from the pymongo side.
I tried mongodb configuration flags, but failed, don't know if there is a way. I am also willing to reconnect to mongodb on every rest call to avoid this, but any ideas/suggestions there.
I was hoping mongo_client should provide onClose() function, for the application to handle disconnections, but could not find any such handler.

How to keep connection with Spring boot, Hibernate and Websphere Application Server

My application uses the frameworks and application server below:
Spring Boot(1.5.4.RELEASE) with hibernate.
Websphere Application Server Liberty for Java on Bluemix
The application works fine however after the running for hours connections time out. See following exception:
2017-09-01T11:40:40.57+0900 [APP/PROC/WEB/0] OUT 2017-09-01 02:40:40,563 [http-nio-8080-exec-2] [5baba2cb-5bfd-4846-b8e0-8782aa729639] [] WARN o.h.e.jdbc.spi.SqlExceptionHelper [SqlExceptionHelper.java:127] - SQL Error: -4499, SQLState: 08001
2017-09-01T11:40:40.58+0900 [APP/PROC/WEB/0] OUT or socket output stream. Error location: Reply.fill() - socketInputStream.read (-1). Message: Connection timed out (Write failed). ERRORCODE=-4499, SQLSTATE=08001
I know Spring boot needs to be set configuration properties in application.properties.
spring.datasource.testOnBorrow=true
spring.datasource.testWhileIdle=true
spring.datasource.timeBetweenEvictionRunsMillis=60000
spring.datasource.numTestsPerEvictionRun=3
spring.datasource.minEvictableIdleTimeMillis=600000
spring.datasource.validationQuery=SELECT 1
However, I found out with Spring boot 1.3+, we must use the implementation-specific settings using their respective prefix (spring.datasource.tomcat., spring.datasource.hikari., and spring.datasource.dbcp2.*), and (apparently) DOES NOT SUPPORT Websphere Application Server Liberty Profile.
My question is how should I configure to keep connections alive (or renew them)?
Thank you in advance!
What datasource are you using? In our case we are using tomcat which is the default option. So we have
# DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.test-while-idle=true
spring.datasource.tomcat.time-between-eviction-runs-millis=300000
spring.datasource.tomcat.validation-query=SELECT 1

Spring Boot - webservice: Connection Refused

I am trying to implement spring boot webservice application as given in spring docs :
https://spring.io/guides/gs/consuming-web-service/
Build was successful, request and response java files was created and , but when executed spring-boot:run , it gives
Caused by: org.springframework.ws.client.WebServiceIOException: I/O error: Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:561)
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390)
at hello.WeatherClient.getCityForecastByZip(WeatherClient.java:30)
at hello.Application.main(Application.java:20)
But the URL is accessible via web browser in eclipse. Kindly help me solve this issue
Make sure all your tests declared with same #SpringBootTest annotation parameters.
I had same issue because of different parameters in two tests. Problem gone when I made all annotations same:
#SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT))
The web Service URL you are trying to call may be not reachable or it gets timeout. Ensure the web Service URL path is correct and is listening. also verify the timeout duration set and the time taken from your request.
PS. Also check if there is some firewall issue at Server side.
For firewall issue, you might need to provide proxy details(proxyHost and proxyPort) In client code.
EDIT:
I am not able to find appropriate blog or something which explains it better. but found one question on stackoverflow which has similar answer : here

Resources