我想知道我需要在這個Spring Initializr 中選擇哪些依賴項來啟動一個使用 Hibernate 和 MySQL 資料庫的 Restful API Spring 應用程式。
我做了一些嘗試,但無法弄清楚。
uj5u.com熱心網友回復:
您將需要 Spring Web WEB 和 Spring Data JPA,以及一些資料庫驅動程式。
.pom 將如下所示:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
uj5u.com熱心網友回復:
如果您使用的是 Maven 專案,則在 pom.xml 中添加這些依賴項,
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
如果您使用的是 Gradle 專案,則在 build.gradle 中添加這些依賴項,
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'
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/316323.html
