oracle-databasespring-boot

Spring Boot application connects to standby (secondary) Oracle database by default


I have multiple Spring Boot applications with database connection. Recently I created another similar application but this time with the version 3.4.4. I have two instances of Oracle database, one is primary, other is standby(secondary). The primary database switch to another after a certain time.

Problem: I connect in THE SAME way like the other applications to database with ldap url. But it connects to always the standby one.

  1. Spring Boot version 3.4.4
  2. Linux server
  3. Application is in podman container as the others but without a pod
  4. Dependency "com.oracle.database.jdbc:ojdbc11" version is 23.2.0.0

Info messages:

2025-04-25T13:20:09.034Z  INFO [custom-service,,] 1 --- [custom-service] [           main] [                                                 ] oracle.jdbc                              : traceId=A1B2C3D.
2025-04-25T13:20:09.036Z  INFO [custom-service,,] 1 --- [custom-service] [           main] [                                                 ] oracle.jdbc                              : Session Attributes:
sdu=1111, tdu=2222222
nt: host=HOSTNAME, port=1521, socketOptions={0=YES, 1=YES, 17=0, 18=false, 2=30000, 20=true, 38=TLS, 23=40, 24=50, 40=false, 25=0}
    socket=null
client profile={oracle.net.encryption_types_client=(), oracle.net.crypto_seed=, oracle.net.authentication_services=(XXX), oracle.net.setFIPSMode=false, oracle.net.kerberos5_mutual_authentication=false, oracle.net.encryption_client=ACCEPTED, oracle.net.crypto_checksum_client=ACCEPTED, oracle.net.crypto_checksum_types_client=()}
onBreakReset=false, dataEOF=false, negotiatedOptions=0x0, connected=false
2025-04-25T13:20:09.037Z  INFO [custom-service,,] 1 --- [custom-service] [           main] [                                                 ] oracle.jdbc                              : traceId=A1B2C3D, anoEnabled=true.
2025-04-25T13:20:09.037Z  INFO [custom-service,,] 1 --- [custom-service] [           main] [                                                 ] oracle.jdbc                              : Got Refused, SessionTraceId = A1B2C3D
2025-04-25T13:20:09.037Z  INFO [custom-service,,] 1 --- [custom-service] [           main] [                                                 ] oracle.jdbc                              : Outbound interrupt timer cancelled null
2025-04-25T13:20:09.037Z  INFO [custom-service,,] 1 --- [custom-service] [           main] [                                                 ] oracle.jdbc                              : Session Attributes:

Error message:

java.sql.SQLRecoverableException: ORA-12514: Cannot connect to database. Service XXXX is not registered with the listener at host HOSTNAME port 1521. (CONNECTION_ID=xxx==)
        at oracle.jdbc.driver.T4CConnection.handleLogonNetException(T4CConnection.java:1099) ~[ojdbc11-23.2.0.0.jar!/:23.2.0.0.0]
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:879) ~[ojdbc11-23.2.0.0.jar!/:23.2.0.0.0]
        at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:1132) ~[ojdbc11-23.2.0.0.jar!/:23.2.0.0.0]
        at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:104) ~[ojdbc11-23.2.0.0.jar!/:23.2.0.0.0]
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:837) ~[ojdbc11-23.2.0.0.jar!/:23.2.0.0.0]
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:664) ~[ojdbc11-23.2.0.0.jar!/:23.2.0.0.0]

I have already checked the release notes of Spring Boot 3.4.4: https://github.com/spring-projects/spring-boot/releases/tag/v3.4.4

This bugfix may be relevant but I am not sure how to solve it. https://github.com/spring-projects/spring-boot/issues/44516

Do I have to add an additional property?

My properties are:

SPRING_DATASOURCE_USERNAME=XXX
SPRING_DATASOURCE_PASSWORD=XXX
SPRING_DATASOURCE_DRIVER_CLASS_NAME=oracle.jdbc.OracleDriver
SPRING_DATASOURCE_URL=jdbc:oracle:thin:@ldap://xxx:3060/xxxx,cn=xx,dc=xx,dc=com

I tried Spring Boot versions:

3.4.5

3.4.4

3.4.3

3.4.2

3.4.1

but none of them worked.


Solution

  • The problem was that my jdbc driver version did not support JDK21.

    Link: https://www.oracle.com/database/technologies/appdev/jdbc-drivers-archive.html

    enter image description here

    I tried these versions and all worked.

    23.8.0.25.04

    23.7.0.25.01

    21.17.0.0