Anton Styopin Anton Styopin - 1 month ago 20
Java Question

Spring boot gradle cannot load sqlserver dependency

I am trying to build a springboot application, with microsoft sql server connection. I build connection to mysql and it worked fine, but now i cannot connect to my mssql database, because springboot gradle script doesn't load the 'com.microsoft.sqlserver:sqljdbc4' jar. I tried to load the jar via gradle script in a non-springboot project and it worked fine. Is springboot doing something i don't know? Or is there another problem?

My gradle-script:

buildscript {
ext {
springBootVersion = '1.4.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'

jar {
baseName = 'BEAT-Surflet'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()
}


dependencies {
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('com.microsoft.sqlserver:sqljdbc4')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework:spring-jms')
compile('org.apache.activemq:activemq-broker')
testCompile('org.springframework.boot:spring-boot-starter-test')
}


Maybe the problem is, that springboot tries to load the version by himself or conflicting because of it. I tried to exlicit give him the version too ('com.microsoft.sqlserver:sqljdbc4:4.0'), but it didn't work either. So why my gradle-script or my springboot project doesn't load the mssql jar?

Answer

I had simmilar issues. I Solved this by using net.sourceforge.jtds 1.3.1. driver. I suggest using this driver for MSSQL databases. Microsoft driver is really bugged and it do not support of some widely used data types.