1

i have the driver dependency in the POM.xml and i am using maven shade plugin to create an Uber Jar. i do see the driver dependency correctly listed in the JAR file. Jar runs fine in intellij but on google dataproc cluster it fails with class not found error.

POM file with dependency:

<dependency>
  <groupId>com.microsoft.sqlserver</groupId>
  <artifactId>sqljdbc4</artifactId>
  <version>4.0.0</version>
</dependency>

Jar listing the dependency classes are in the JAR

>target % jar tf app.jar | grep SQLServerDriver
com/microsoft/sqlserver/jdbc/SQLServerDriver.class
com/microsoft/sqlserver/jdbc/SQLServerDriverBooleanProperty.class
com/microsoft/sqlserver/jdbc/SQLServerDriverIntProperty.class
com/microsoft/sqlserver/jdbc/SQLServerDriverPropertyInfo.class
com/microsoft/sqlserver/jdbc/SQLServerDriverStringProperty.class

Here is my Application YAML file which has the driver listed

  datasource:
    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
    jdbc-url:"jdbc:sqlserver://sqlserver.dev.db.xyz.com;databaseName=db01;multiSubnetFailover=true"
    username: "sa_user"

Below is the full error message:

24/11/29 15:48:38 WARN org.springframework.context.annotation.AnnotationConfigApplicationContext: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'dataSource': Could not bind properties to 'DataSource' : prefix=spring.datasource, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.datasource' to javax.sql.DataSource
***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to bind properties under 'spring.datasource' to javax.sql.DataSource:

    Property: spring.datasource.driver-class-name
    Value: "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    Origin: class path resource [application.yaml] from app.jar - 11:24
    Reason: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver

Action:

Update your application's configuration
1
  • I'm not sure what the problem is but why are you using the oldest possible sql server jdbc driver? Unless you want to connect to sql server 2000 or something, there's very little need for anything below version 10 Commented Jan 28 at 14:49

1 Answer 1

0

I think the problem is that while the SQL Server JDBC is present within your Uber JAR, it’s not being loaded by the application’s classloader at runtime within the Dataproc environment. This is a common issue with shaded JARs and JDBC drivers.

What you can do is to specify the driver class directly in the JDBC URL itself. This bypasses the need for the classloader to locate the driver class separately:

jdbc-url: "jdbc:sqlserver://sqlserver.dev.db.xyz.com;databaseName=db01;multiSubnetFailover=true;driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver"

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, tried this suggestion but still the same result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.