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

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

Related

How to log Websphere connection pool information like active connections in spring boot application

We are using Websphere liberty 20.0.0.12 and spring boot (parent) version 2.0.5.
I can find the connection pool information in the JConsole.
How can I print Websphere connection pool information in application logs?
(Read comments of approved answer if using liberty server instead of traditional websphere application server)
IBM support doc at https://www.ibm.com/support/pages/how-enable-connection-pool-trace-websphere-application-server describes how to enable printing of various connection pool stats in the trace log for traditional WAS, for Liberty, you'll use the same trace specification WAS.j2c=all:RRA=all(you don't need Transaction) and put a logging element in your server config file (typically server.xml). See Liberty doc at https://openliberty.io/docs/latest/log-trace-configuration.html for more info.

Spring boot actuator trying to make DB connection

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

How to configure auto reconnection with hikari in SpringBoot application?

We are using SpringBoot 2.1.x version so Hikari is the default DataSource implementation. However, I am not sure how to configure Hikari settings to auto reconnect to our Oracle database after database maintenance/restart or network connection issue.
We have the following hikari settings but it does not seem to help.
account.datasource.url: jdbc:oracle:thin:#myserver:1521:DEV
account.datasource.username: user
account.datasource.password: xxxx
account.datasource.driverClassName: oracle.jdbc.driver.OracleDriver
account.datasource.hikari.connection-timeout: 30000
account.datasource.hikari.maximum-pool-size: 3
account.datasource.hikari.idle-timeout: 60000
account.datasource.hikari.max-lifetime: 1800000
account.datasource.hikari.minimum-idle: 2
It failed to reconnect after network connection to the database got restored.
Failed to obtain JDBC Connection; nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30033ms.
Any other account.datasource.hikari.xxxxx will help to auto reconnect to the database ?
From the HikariCP docs:
connectionTestQuery
If your driver supports JDBC4 we strongly
recommend not setting this property. This is for "legacy" drivers that
do not support the JDBC4 Connection.isValid() API. This is the query
that will be executed just before a connection is given to you from
the pool to validate that the connection to the database is still
alive. Again, try running the pool without this property, HikariCP
will log an error if your driver is not JDBC4 compliant to let you
know. Default: none
So I'd suggest verifying that your JDBC Driver is actually JDBC4 compliant. If it's not - set the above property.

How to enable jmxremote authentication for MobileFirst Platform on Tomcat

I try to configure login/password authentication for jmxremote connection on Tomcat 7 and MFP 7.1
With the properties -Dcom.sun.management.jmxremote.authenticate=false in file setenv.sh, all works fine. I can see the runtimes in the MFP Operational Console
When I change the properties -Dcom.sun.management.jmxremote.authenticate to true, I don't be able to see the runtime in the MobileFirst Operational Console and I have the following error in the file catalina.out
Exception in thread Initialization thread for Worklight runtime prod" java.lang.RuntimeException: Timeout while waiting for the management service to start up.120 secs.
Thanks
com.sun.management.jmxremote.authenticate=true means that you activate JMX on Tomcat with client authentication based on a user ID and password, without SSL. In this case other properties are required. See for example https://jazz.net/help-dev/clm/index.jsp?re=1&topic=/com.ibm.jazz.repository.web.admin.doc/topics/t_server_mon_tomcat_option2.html&scope=null.

JSTL SQL setDataSource not working with Webshpere 8.5

<sql:setDataSource var="TCIT" scope="application"
driver="${driver}"
url="${url}"
user="${username}"
password="${password}" />
The above code is used in a legacy application deployed in OC4J that is being migrated to WebSphere 8.5. The properties in {} above are fetched from a property file. Ensured the values are coming correctly form there. However, when the database connection is created the application is encountering the following exception: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver" . I have the ojdbc14.jar in the WEB-INF/lib folder, still facing the issue.
Finally the issue got resolved creating a JDBC connection pool at Application server level. Turns out Websphere does not allow the connection to be created using the above method. Below is the modified tag that is using JNDI lookup for accessing the JDBC connection pool at application level.
<sql:setDataSource var="connPool" scope="application" dataSource="${jndi.devPool}"/>

Resources