【问题标题】:SQL Server dependencies in Spring Boot Gradle Java applicationSpring Boot Gradle Java 应用程序中的 SQL Server 依赖项
【发布时间】:2023-03-10 00:47:01
【问题描述】:

我正在尝试使用 Gradle 将数据库连接到我的 Spring Boot 应用程序。 在互联网上,我只使用 pom.xml 文件找到 Maven 项目的示例。 我不确定,但我认为 build.gradle 是 Gradle 中的等价物?我应该添加什么来添加对 Microsoft SQL Server 的支持?

这是我现在的 build.gradle:

plugins {
    id 'org.springframework.boot' version '2.3.3.RELEASE'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    id 'java'
    id 'application'
}

group = 'Project'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
    mavenCentral()
}

application{
    mainClassName 'project.rlstop.Publisher'
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    runtimeOnly 'mysql:mysql-connector-java'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    implementation group: 'org.glassfish.jersey.bundles', name: 'jaxrs-ri', version: '2.+'
    implementation group: 'org.glassfish.jersey.containers', name: 'jersey-container-servlet', version: '2.+'

    // https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api
    implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.+'
    // https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime
    implementation group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.+'



    // Grizzly will host the service
    implementation group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-http', version: '2.+'


    // Logging
    implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.+'
    implementation group: 'org.slf4j', name: 'slf4j-simple', version: '2.+'
}

test {
    useJUnitPlatform()
}

【问题讨论】:

    标签: java sql-server spring-boot gradle


    【解决方案1】:

    我不确定,但我认为 build.gradle 是 Gradle 中的等价物?

    是的,是的。 build.gradle 之于 Gradle 就像 pom.xml 之于 Maven。

    我应该添加什么来添加对 Microsoft SQL Server 的支持?

    您当前对声明的 MySQL JDBC 驱动程序有依赖关系:

    runtimeOnly 'mysql:mysql-connector-java'
    

    要使用 MS SQL Server,您需要将其替换为

    runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
    

    您可以使用Spring Initializr 探索一个框架项目。您也可以参考Reference Documentation,了解如何配置数据源属性以连接到您的 MS SQL Server。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-29
      • 2018-10-07
      • 2016-09-17
      • 2021-06-21
      • 1970-01-01
      • 1970-01-01
      • 2015-06-28
      • 2020-03-31
      相关资源
      最近更新 更多