我正在尝试使用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()
}

最佳答案


是的。 build.gradle是Gradle的,而pom.xml是Maven的。

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

runtimeOnly 'mysql:mysql-connector-java'
要使用MS SQL Server,您需要将其替换为
runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
您可以使用Spring Initializr探索一个骨架项目。您也可以引用Reference Documentation,以获取有关如何配置数据源属性以连接到MS SQL Server的说明。

关于java - Spring Boot Gradle Java应用程序中的SQL Server依赖项,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63951289/

10-14 20:21
查看更多