简体   繁体   English

Spring Boot Gradle Java 应用程序中的 SQL Server 依赖项

[英]SQL Server dependencies in Spring Boot Gradle Java application

I am trying to connect a database to my Spring Boot application using Gradle.我正在尝试使用 Gradle 将数据库连接到我的 Spring Boot 应用程序。 On the internet I only find examples for Maven projects, using the pom.xml file.在互联网上,我只找到 Maven 项目的示例,使用 pom.xml 文件。 I don't know for sure, but I think build.gradle is the equivalent in Gradle?我不确定,但我认为 build.gradle 是 Gradle 中的等价物? What should I add to it to add support for Microsoft SQL Server?我应该添加什么来添加对 Microsoft SQL Server 的支持?

This is my build.gradle right now:这是我现在的 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()
}

I don't know for sure, but I think build.gradle is the equivalent in Gradle?我不确定,但我认为 build.gradle 是 Gradle 中的等价物?

Yes, it is.是的。 build.gradle is to Gradle what pom.xml is to Maven. build.gradle于 Gradle 就像pom.xml于 Maven。

What should I add to it to add support for Microsoft SQL Server?我应该添加什么来添加对 Microsoft SQL Server 的支持?

You currently have a dependency to the MySQL JDBC driver declared:您当前有对 MySQL JDBC 驱动程序的依赖声明:

runtimeOnly 'mysql:mysql-connector-java'

To use MS SQL Server, you need to replace that with要使用 MS SQL Server,您需要将其替换为

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

You may explorer a skeleton project using the Spring Initializr .您可以使用Spring Initializr探索一个骨架项目。 You may also refer to the Reference Documentation for instructions on how to configure the data source properties to connect to your MS SQL Server.您还可以参考参考文档以获取有关如何配置数据源属性以连接到 MS SQL Server 的说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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