Spring-Boot: Creating Your First Application
Introduction Spring Boot is a lightweight framework that can complete most of the configuration work for Spring-based applications. In this tutorial, you will learn how to use Spring Boot's starters, features, and executable JAR file structure to quickly create a Spring-based application that can run directly. This article uses IDEA as the development tool and Gradle as the build tool to create a simple SpringBoot application, without involving database configuration for now. Creating with IDEA
目录4 个章节
Introduction
Spring Boot is a lightweight framework that can complete most of the configuration work for Spring-based applications. In this tutorial, you will learn how to use Spring Boot's starters, features, and executable JAR file structure to quickly create a Spring-based application that can run directly. This article uses IDEA as the development tool and Gradle as the build tool to create a simple SpringBoot application, without involving database configuration for now.
Creating with IDEA
Create a new project and select Spring Initializr

Next

Configure dependencies
The dependencies I selected are all shown on the right.
For Web, I selected REST support, which makes it convenient to write REST applications—you can just use mapping.
For the database, I selected JDBC and the MySQL driver. (However, they won't be used in the first application.)

The next step is to choose the folder to save the project. I won't take a screenshot here~
Finally, click the 完成 button, and Gradle will start building the project. This process takes a while, so please be patient.
Writing Code
After waiting for Gradle to finish building, you can start writing REST endpoints. The code is as follows.
package cn.deali.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
// 排除引入数据源配置类
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class DemoApplication {
@RequestMapping("/")
String index() {
return "hello world";
}
@RequestMapping("hello")
String hello() {
return "hello";
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Run & Test
Click Run - Run DemoApplication to run the Spring Boot project.
If everything is normal, take a look at the output in the Run window.

At this point, open a browser and enter
http://127.0.0.1:8080
or
http://127.0.0.1:8080/hello
to see the running result.
_EOF_
Spring-Boot: Creating Your First Application
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
JavaWeb开发---Servlet的生命周期实验
前言 Servlet是运行在服务器端的程序,它的运行状态由Servlet容器(简称容器)来维护。 通常,在容器收到客户对Servlet的请求时,容器会判断这个Servlet是否为第一次被访问,如果是第一次被访问,则会创建一个Servlet实例同时调用该实例的init()方法,进行初始化。 每个Servlet只会被创建一个实例,同时也只会被初始化一次。然后将这个实例一直保存在内存中,对所有的请求进行
2022-05-27 · Java · 约 1 分钟
Java开发:JDK安装和环境配置
前言 环境配置是开发中最基础的部分,不过最近有很多新入坑的同学,都在问怎么安装JDK和配置环境,索性写一篇。 这里要注意一下,在Windows平台和Linux平台下做开发是不同的,Windows平台开发Java需要自己手动配置JDK的环境变量,而大多数Linux都是不需要的,安装了OpenJDK就可以了(可能很多发行版都自带了OpenJDK),这点是比较方便的。 下载Java JDK Window
2023-02-08 · Java · 约 1 分钟
Maven国内镜像配置
配置maven安装目录下的conf/settings.xml。 在<mirrors>节点下,设置: mirror idaliyun-public/id mirrorOf*/mirrorOf namealiyun public/name urlhttps://maven.aliyun.com/repository/public/url /mir
2021-12-18 · Java · 约 1 分钟
在Linux-Ubuntu上配置开发JavaFx程序-(更新)
前言 不清楚什么原因,网络上关于JavaFx的中文资料很少,并且都很老,所以建议大家有兴趣学习JavaFx还是看官方文档比较好,而且貌似部分人不看好JavaFx。 关于Swing的资料倒是要多很多。我觉得挺奇怪的,从设计上来将,还是JavaFx高明一些嘛。 PS:经过近一周的折腾和探索,发现OpenJDK使用JavaFX真的好多坑~ OpenJDK 和 Oracle JDK的配置是有差别的,这里推
2022-05-27 · Java · 约 1 分钟
讨论
共 0 条加载评论中…