Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Unable to load class: com.microsoft.sqlserver.jdbc.SQLServerDriver

I've created a new Spring Boot project. I'm trying to setup a DataSource to use MSSQL. However I seem to be getting the error "Unable to load class: com.microsoft.sqlserver.jdbc.SQLServerDriver"

I've placed the file jdbcsql4.jar in a folder in my project /lib/jdbcsq4.jar

In my pom.xml file I've added the following:

<dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>sqljdbc4</artifactId>
        <version>4.0</version>
        <scope>system</scope>
        <optional>true</optional>
        <systemPath>${basedir}/lib/sqljdbc4.jar</systemPath>
    </dependency>

I have an application.properties file, and I'm defining the database credentials like this:

secondary.datasource.url = jdbc:sqlserver://1.1.1.1:50109
secondary.datasource.username = sa
secondary.datasource.password = mypassword
secondary.datasource.driver-class-name =     com.microsoft.sqlserver.jdbc.SQLServerDriver

Can anyone possibly indicate where I may be going wrong?

like image 778
SheppardDigital Avatar asked Nov 23 '15 11:11

SheppardDigital


2 Answers

I managed to solve this issue by following the instructions in this link http://claude.betancourt.us/add-microsoft-sql-jdbc-driver-to-maven/

EDIT: The original link above no longer exists, but here's a similar link. http://biercoff.com/add-microsoft-sql-jdbc-driver-to-maven/

like image 97
SheppardDigital Avatar answered Oct 20 '22 06:10

SheppardDigital


For the ppl who facing these issue. Add dependency in POM. Microsoft finally made the driver available on the Maven Central Repository.

<dependency>
 <groupId>com.microsoft.sqlserver</groupId>
 <artifactId>mssql-jdbc</artifactId>
 <version>6.1.0.jre8</version>
</dependency>

you can check here. Microsoft link

like image 35
Rks Avatar answered Oct 20 '22 04:10

Rks