【问题标题】:Initilize Spring application with start.spring.io使用 start.spring.io 初始化 Spring 应用程序
【发布时间】:2021-10-13 19:29:54
【问题描述】:
我想知道我需要在这个 Spring Initializr 中选择哪些依赖项来启动一个使用 Hibernate 和 MySQL 数据库的 Restful API Spring 应用程序。
我做了一些尝试,但无法弄清楚。
【问题讨论】:
标签:
java
spring
spring-boot
hibernate
【解决方案1】:
您将需要 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>
【解决方案2】:
如果您使用的是 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'
}