英文:
SQL Server dependencies in Spring Boot Gradle Java application
问题
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 am trying to connect a database to my Spring Boot application using Gradle.
On the internet I only find examples for Maven projects, using the pom.xml file.
I don't know for sure, but I think build.gradle is the equivalent in Gradle? What should I add to it to add support for Microsoft SQL Server?
This is my build.gradle right now:
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()
}
答案1
得分: 1
> 我不能确定,但我认为在Gradle中的等效部分是 build.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 查看一个基本项目的结构。您还可以参考 参考文档,了解如何配置数据源属性以连接到您的 MS SQL Server。
1: https://start.spring.io/#!type=gradle-project&language=java&platformVersion=2.3.4.RELEASE&packaging=jar&jvmVersion=11&groupId=com.example&artifactId=demo&name=demo&description=为 Spring Boot 的演示项目&packageName=com.example.demo&dependencies=sqlserver,web,data-jpa
2: https://docs.spring.io/spring-boot/docs/2.3.4.RELEASE/reference/htmlsingle/#boot-features-connect-to-production-database
英文:
> I don't know for sure, but I think build.gradle is the equivalent in Gradle?
Yes, it is. build.gradle
is to Gradle what pom.xml
is to Maven.
> What should I add to it to add support for Microsoft SQL Server?
You currently have a dependency to the MySQL JDBC driver declared:
runtimeOnly 'mysql:mysql-connector-java'
To use MS SQL Server, you need to replace that with
runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
You may explorer a skeleton project using the 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论