Unable to connect to Sql Server Db with Spring Boot Starter Partent 2.7.*

603 Views Asked by At

I have a small spring boot application that has to connect to a Sql Server DB. When I run the application with spring-boot-starter-parent version 2.6.* everything works. But when I switch to version 2.7.* I get this error:

com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target". ClientConnectionId:66a65f3c-2b09-4a06-975a-3e3ea35a11ee
Caused by: javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Any suggestion on which could be the problem? Thanks

1

There are 1 best solutions below

0
On

I faced the same issue with spring boot 2.7.4

it turns out that since 2.7.0 the JDBC Driver 10.2 for SQL Server is used
instead of 9.4.1.jre8 for 2.6.x

So you've 1 of 2 solutions that worked for me:

1. Use the older version of mssql-jdbc driver

    <properties>    
        <mssql-jdbc.version>9.4.1.jre8</mssql-jdbc.version>
    </properties>

2. Or ask the driver to just trust the whatever the Sql server certiticate is
you can do so by adding this to the connection string:

jdbc:sqlserver://hOSt:pORt;databaseName=dbName;encrypt=true;trustServerCertificate=true


Personally I didn't prefer to trust any certificate blindly so went for 1
specially it saves you the hassle of managing a self-signed certificate for your sql server