在前面的文章中介绍了如何使用gradle的基础知识,这篇文章在某种程度上才是真正意义上的第一个hello world,这里使用一个简单的spring boot的例子,通过gradle进行编译和构建以及确认。
事前准备
环境准备
组件/框架 | 版本 |
---|---|
JDK | 1.8.0 |
Gradle | 4.10.2 |
Spring Boot | 2.1.1 |
liumiaocn:springboot liumiao$ gradle -v
------------------------------------------------------------
Gradle 4.10.2
------------------------------------------------------------
Build time: 2018-09-19 18:10:15 UTC
Revision: b4d8d5d170bb4ba516e88d7fe5647e2323d791dd
Kotlin DSL: 1.0-rc-6
Kotlin: 1.2.61
Groovy: 2.4.15
Ant: Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM: 1.8.0_191 (Oracle Corporation 25.191-b12)
OS: Mac OS X 10.14 x86_64
liumiaocn:springboot liumiao$
spring boot demo应用
目录结构
使用https://start.spring.io/或者自己手动创建如下结构的目录结构
liumiaocn:springboot liumiao$ tree
.
├── build.gradle
├── settings.gradle
└── src
└── main
├── java
│ └── com
│ └── liumiaocn
│ └── springbootdemo
│ └── SpringbootdemoApplication.java
└── resources
└── application.properties
7 directories, 4 files
liumiaocn:springboot liumiao$
spring boot相关说明
详细请参看spring boot相关说明,本文不再赘述:
https://blog.csdn.net/liumiaocn/article/details/83548217
liumiaocn:springboot liumiao$ cat src/main/resources/application.properties
liumiaocn:springboot liumiao$ cat src/main/java/com/liumiaocn/springbootdemo/SpringbootdemoApplication.java
package com.liumiaocn.springbootdemo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping