【问题标题】:Spring boot gradle cannot load sqlserver dependencySpring boot gradle 无法加载 sqlserver 依赖
【发布时间】:2016-10-24 09:11:19
【问题描述】:

我正在尝试构建一个带有 microsoft sql server 连接的 springboot 应用程序。我建立了与 mysql 的连接,它工作正常,但现在我无法连接到我的 mssql 数据库,因为 springboot gradle 脚本没有加载 'com.microsoft.sqlserver:sqljdbc4' jar。我试图通过 gradle 脚本在非 springboot 项目中加载 jar,它工作正常。 springboot 是在做我不知道的事情吗?还是有其他问题?

我的 gradle 脚本:

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')
}

也许问题是,springboot 尝试自己加载版本或因此而发生冲突。我也试图明确地给他版本('com.microsoft.sqlserver:sqljdbc4:4.0'),但它也不起作用。那么为什么我的 gradle-script 或者我的 springboot 项目没有加载 mssql jar 呢?

【问题讨论】:

标签: java sql-server spring gradle spring-boot


【解决方案1】:

我有类似的问题。我通过使用 net.sourceforge.jtds 1.3.1 解决了这个问题。司机。我建议将此驱动程序用于 MSSQL 数据库。 Microsoft 驱动程序确实有 bug,它不支持一些广泛使用的数据类型。

【讨论】:

  • JTDS 不支持某些 SQL Server 类型,如 UniqueIdentifier,IIRC 也不支持 JDBC4?无论哪种方式,JTDS 都不适用于我的项目,我必须使用 MS 驱动程序
【解决方案2】:

我猜你真的希望 Spring Boot 而不是 Gradle 能够使用 MS SQL Server —— Gradle 只是将依赖项放在类路径上。

您可能需要在应用程序属性/yml 文件中指定spring.datasource.driver-class-name。请参阅文档的 Working with SQL Databases 部分。

祝你好运。

【讨论】:

  • 不,我真的想让 gradle 加载 mssql jar 文件。
猜你喜欢
  • 2019-01-27
  • 1970-01-01
  • 2018-10-06
  • 2021-09-08
  • 2022-12-23
  • 2021-12-31
  • 1970-01-01
  • 2016-09-17
  • 1970-01-01
相关资源
最近更新 更多