1.Spring Initializr的使用
2019-06-22 本文已影响0人
秋林格瓦斯
1. 生成骨架
- 访问 https://start.spring.io/ 使用Spring Initialzr生成骨架

- 生成 com.lgp.spring.zip 下载到工程中,解压缩.
3.IDEA 中open这个工程, 设置maven. 右边maven projects导入pom.xml. 刷新
- 项目中src/main/java, src/main/resources出现颜色. 表示搞定了环境问题.
项目结构如下:

2. 第一个小demo
2.1 代码和输出结果
package com.lgp.spring;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@RequestMapping("/hello")
public String hello(){
return "hello world";
}
}
因为application.properties中没有配置任何信息,所以默认使用8080端口号.
下面,我们访问测试下.

可以看到输出结果为hello world , 结果正确.
由于我们在pom.xml中依赖了actuator. 可以访问一下路径进行健康检查,

2.2 通过mvn打jar包
在terminal中通过mvn命令打包,跳过单元测试:
mvn clean package -Dmaven.test.skip
一定要在pom文件的文件夹中执行mvn命令.