访问 Spring 生成一个 Spring Boot 的项目。
填写 Group 和 Artifact , 然后点 Generate Project 生成你的工程。
使用 IntelliJ 导入工程。
选择工程目录
然后反复 Next 吧。
最后我们的工程目录是这样的。
src/main/java 下的 DemoApplication 是程序的入口。 src/main/resources 下的 application.properties 是个配置文件。 src/test/java 下的 DemoApplicationTests 是单元测试的入口。 打开 pom.xml ,可以看到有两个默认依赖配置
spring-boot-starter : 核心模块,包括自动配置支持、日志和YAML spring-boot-starter-test : 测试模块, 包括JUnit、Hamcrest、Mockito <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
要使用 Web 相关的服务,需要引入 Web 模块,需添加 spring-boot-starter-web 模块:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
package 命名为 controller (可根据个人习惯修改) HelloController 类,内容如下 @RestController
public class HelloController{
@RequestMapping("/hello")
public String index() {
return "Hello World";
}
}
http://localhost:8080/hello ,可以看到页面输出 Hello World 所有的学习都是由 Hello World 开始,下次写写如何实现注册登录服务吧。
后续所有 Spring Boot 相关的学习源码,我都会上传到这个仓库地址上 SpringBoot-Learning