简体   繁体   中英

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?

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.

I'm guessing you really want Spring Boot, not Gradle, to be able to use MS SQL Server -- Gradle just puts the dependency on the classpath.

You may need to specify spring.datasource.driver-class-name in you application properties/yml file. See the Working with SQL Databases section of the documentation.

Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM