0Pricing
GraphQL APIs with Spring Boot · 课时

为 GraphQL 设置 Spring Boot

配置新的 Spring Boot 应用,并集成开发 GraphQL API 所需的依赖。

为 GraphQL 设置 Spring Boot 是 CoddyKit 上的免费 GraphQL APIs with Spring Boot 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 GraphQL APIs with Spring Boot 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 GraphQL APIs with Spring Boot 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Get Ready for GraphQL!

Time to build a GraphQL API with Spring Boot. You’ll configure a project and add the GraphQL dependencies that bring these two together.

Create Your First Project

The fastest start is Spring Initializr at start.spring.io: pick Maven or Gradle, Java, the latest Spring Boot, and add the Spring Web dependency.

Initial Project Structure

Unzipped, you get a standard layout. The *Application.java class holds the main method that boots your app — run it to confirm setup before adding GraphQL.

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {
  public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
  }
}

Bring in GraphQL Power

Add GraphQL power with one dependency: spring-boot-starter-graphql. It bundles the engine, auto-configures it, and even gives you a GraphiQL UI.

Maven: Adding the Starter

On Maven, drop spring-boot-starter-graphql into the <dependencies> block of your pom.xml and Maven pulls in every GraphQL library.

<dependencies>
  <!-- Existing dependencies like spring-boot-starter-web -->
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-graphql</artifactId>
  </dependency>
</dependencies>

Gradle: Adding the Starter

On Gradle, add the same spring-boot-starter-graphql dependency to your build.gradle using the implementation configuration.

dependencies {
  // Existing dependencies like spring-boot-starter-web
  implementation 'org.springframework.boot:spring-boot-starter-graphql'
}

Project Layout for GraphQL

Spring Boot auto-discovers your schema in src/main/resources/graphql. Create that folder and an empty schema.graphqls — your API’s contract.

Running Your GraphQL App

Run the app from your IDE, or with ./mvnw spring-boot:run / ./gradlew bootRun. Watch for “Started DemoApplication” and Tomcat on port 8080.

Verify GraphQL Endpoint

The starter auto-configures a /graphql endpoint plus a GraphiQL UI. Open localhost:8080/graphiql — if it loads, your setup works.

Check Your Setup Knowledge

You've learned how to set up a basic Spring Boot project and integrate GraphQL dependencies. Let's quickly review what you need to do to get started.

Setup Complete! What's Next?

Setup done! You used Spring Initializr, added the GraphQL starter, and prepped your schema file. Next, design your first schema in SDL.

常见问题解答

「为 GraphQL 设置 Spring Boot」课时是免费的吗?

是的 — 「为 GraphQL 设置 Spring Boot」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 GraphQL APIs with Spring Boot 课程的其余内容,请升级到 CoddyKit PRO。 GraphQL APIs with Spring Boot 课程共包含 4 节课。

「为 GraphQL 设置 Spring Boot」这节课中我会学到什么?

配置新的 Spring Boot 应用,并集成开发 GraphQL API 所需的依赖。 你通过在浏览器中直接运行的动手代码来练习 GraphQL APIs with Spring Boot,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 GraphQL APIs with Spring Boot 需要有经验吗?

无需任何先前经验。CoddyKit 上的 GraphQL APIs with Spring Boot 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。

「为 GraphQL 设置 Spring Boot」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 GraphQL APIs with Spring Boot 课中编写并运行代码吗?

能。每节 GraphQL APIs with Spring Boot 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 什么是 GraphQL
  2. 为 GraphQL 设置 Spring Boot
  3. 设计您的第一个 GraphQL 模式
  4. GraphQL 与 REST:选择合适的方法
← 返回 GraphQL APIs with Spring Boot