In my Spring boot(2.0.7 RELEASE) application I am not able to manually set/override the timeout for the database connections in the application.properites file. I am using JPA, Hibernate, Tomcat connection pool and Postgres.
I've researched thoroughly and found very similar questions :
- Overriding timeout for database connection in properties file
- JPA query timeout parameters ignored but @Transaction annotation works
The reason I ask new question is because neither of the questions above have an accepted answer nor a confirmed working solution. I tried including each proposed solution in my application.properties file with no success.
Also, as mentioned in question 2: if I add parameter 'timeout = someSeconds' in the @Transactional annotation, the connection timeouts as expected but if I try extracting it in the application.properties it fails and timeouts for the default time. The problem here is that I want all connections to timeout in the given time not only the transactions.
Things I've tried in the application.properties (The desired timeout is 4 seconds):
- spring.jpa.properties.javax.persistence.query.timeout=4000
- spring.jdbc.template.query-timeout=4
- spring.transaction.defaultTimeout=4
- spring.datasource.tomcat.validation-query-timeout=4
Materials I've read:
- http://www.masterspringboot.com/configuration/web-server/configuring-tomcat-connection-pool-on-spring-boot
- https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
- https://www.baeldung.com/spring-boot-tomcat-connection-pool
- https://www.objectdb.com/java/jpa/query/setting#Query_Hints_
Am I missing some property? Does anyone know why the timeout can't be overridden via the application.properties file?
Thanks in advance.