【问题标题】:Initilize Spring application with start.spring.io使用 start.spring.io 初始化 Spring 应用程序
【发布时间】:2021-10-13 19:29:54
【问题描述】:

我想知道我需要在这个 Spring Initializr 中选择哪些依赖项来启动一个使用 Hibernate 和 MySQL 数据库的 Restful API Spring 应用程序。

我做了一些尝试,但无法弄清楚。

【问题讨论】:

  • Spring web + Spring Data Jpa +MySQL Driver ,您也可以使用“Spring Boot DevTools”避免代码更改后手动重启服务器,您需要在application.properties中配置Hibernate和与DB的连接文件 .这个答案我帮你:stackoverflow.com/questions/25930191/…

标签: 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'
    }
    

    【讨论】:

      猜你喜欢
      • 2013-07-02
      • 2013-06-16
      • 1970-01-01
      • 1970-01-01
      • 2017-01-10
      • 2020-06-30
      • 2012-05-03
      • 2015-03-06
      • 2018-11-13
      相关资源
      最近更新 更多