STS 新建一个spring-boot rest 项目

1.打开STS,右键选择项目

2.下一步选择consuming rest,红色箭头指向,点击finsh 

3.代码修改 
Application.java

package hello;import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.client.RestTemplate;@SpringBootApplication
public class Application implements CommandLineRunner {private static final Logger log = LoggerFactory.getLogger(Application.class);public static void main(String args[]) {SpringApplication.run(Application.class);}@Overridepublic void run(String... strings) throws Exception {RestTemplate restTemplate = new RestTemplate();Quote quote = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random", Quote.class);log.info(quote.toString());}
}

GreetingController.java

package hello;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;/**
* <p></p>
* @title          - GreetingController.java
* @author         - ningzhong.zeng
*/
@Controller
@RequestMapping("/hello-world")
public class GreetingController {@ResponseBody@RequestMapping(value="/greeting", method=RequestMethod.GET)public Quote greeting(@RequestParam(value="name", defaultValue="World") String name) {Value value = new Value();value.setId(1111111L);value.setQuote(name);Quote quote = new Quote();quote.setValue(value);quote.setType("type");return quote;}
}

Qutoe.java

package hello;import com.fasterxml.jackson.annotation.JsonIgnoreProperties;@JsonIgnoreProperties(ignoreUnknown = true)
public class Quote {private String type;private Value value;public Quote() {}public String getType() {return type;}public void setType(String type) {this.type = type;}public Value getValue() {return value;}public void setValue(Value value) {this.value = value;}@Overridepublic String toString() {return "Quote{" +"type='" + type + '\'' +", value=" + value +'}';}
}

Value.java

package hello;import com.fasterxml.jackson.annotation.JsonIgnoreProperties;@JsonIgnoreProperties(ignoreUnknown = true)
public class Value {private Long id;private String quote;public Value() {}public Long getId() {return this.id;}public String getQuote() {return this.quote;}public void setId(Long id) {this.id = id;}public void setQuote(String quote) {this.quote = quote;}@Overridepublic String toString() {return "Value{" +"id=" + id +", quote='" + quote + '\'' +'}';}
}

application.properties

server.port : 9000
management.port: 9001
management.address: 127.0.0.1

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.springframework</groupId><artifactId>gs-consuming-rest</artifactId><version>0.1.0</version><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.3.2.RELEASE</version></parent><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId></dependency><dependency><groupId>org.apache.tomcat.embed</groupId><artifactId>tomcat-embed-core</artifactId></dependency><dependency><groupId>org.apache.tomcat.embed</groupId><artifactId>tomcat-embed-logging-juli</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

4.运行 

5.访问 
http://localhost:9000/hello-world/greeting

http://localhost:9001/hello-world/greeting 
http://localhost:9001/health

spring-boot (9)---STS 新建一个spring-boot rest 项目相关推荐

  1. Spring学习笔记:第一个Spring Boot程序HelloWorld

    Spring学习笔记:第一个Spring Boot程序HelloWorld 一.跟着 Spring 了解技术趋势 1.看看 Spring 5.x 的改变暗示了什么 2.Spring Boot 和 Sp ...

  2. 【暑假学习笔记】之——用Intellij idea新建一个java web+Servlet项目(有实例)——idea中快速重写父类的方法

    Intellij idea中快速重写父类方法 在写java文件时,有时候需要重写父类方法,但在idea中创建java文件时并不会像eclipse一样可以选择父类,但是重写父类方法其实只需要这样做: 鼠 ...

  3. 使用 Spring Boot CLI 运行第一个Spring boot程序

    简介 Spring Boot CLI是Spring Boot的命令行界面.它可以用来快速启动Spring.  它可以运行Groovy脚本.  Spring Boot CLI是创建基于Spring的应用 ...

  4. Spring Boot (1) 构建第一个Spring Boot工程

    Spring boot简介 spring boot是spring官方推出的一个全新框架,其设计目的是用来简化新spring应用的初始搭建以及开发过程. Spring boot特点 1.化繁为简,简化配 ...

  5. Eclipse新建一个Spring项目(最基础)

    我在这里使用eclipse新建一个最基础的spring项目,提高初学者的实践能力,如果看完这篇文章后,你感到其实spring不难,可以轻松学会学好,我就达到写本篇文章的目的了. 首先,笼统介绍一下,什 ...

  6. idea 新建一个spring项目

    1.首先新建一个project 2.如图 3.选择工程的依赖 4.没用的文件可以删除 转载于:https://www.cnblogs.com/banml/p/11345001.html

  7. xxx is already defined as object xxx+intellij新建一个scala的maven项目+找不到或无法载入主要类别hello问题解决

    ---------------------------------------------------------------------------------------------------- ...

  8. 使用Spring boot开发一个接口 - TODO应用中新建一个TASK

    spring initializr spring boot官方提供了很方便的初始化项目的方法,即spring initializr.可以直接在IDEA中创建,或在https://start.sprin ...

  9. 创建并运行一个 Spring Boot 项目

    创建并运行一个 Spring Boot 项目 引言 第一个 Spring Boot 项目 1. 创建一个 spring boot 项目 第一步 第二步 第三步 第四步 2. 验证 第一步 第二步 3. ...

最新文章

  1. R聚类(整群)抽样(Cluster Sampling)
  2. Android应用程序窗口(Activity)的测量(Measure)、布局(Layout)和绘制(Draw)过程分析(上)...
  3. ubuntu/deepin常用软件清单(都是使用sudo apt-get install安装方式)
  4. ANdroid O MeidiaPlayer 深入理解(一)
  5. 【iOS开发】企业版证书($299)In-House方式发布指南
  6. symbian c++ 开发环境Carbide.c++搭建
  7. 同名字的数值求和插入行_EXCEL条件求和的6种技术,你会的超过3种吗?
  8. 实例应用 自定义页面taglib标签
  9. 源码编译php mysql_linux下apache+mysql+php开发环境纯源代码编译搭建(转)
  10. 火狐浏览器安装java插件下载_如何在 Firefox 浏览器安装 java 插件
  11. Python3+Scrapy实现网页爬虫
  12. 二叉平衡树平衡方法(RR、LL、RL、LR)
  13. hoolilaw案例分析:在美国如何治理扰民邻居
  14. 对国内游戏产业的无力吐槽
  15. 网络游戏长连接与短连接的差异
  16. 当领导招了100个初级开发去做3个资深开发的工作
  17. IPMP、PMP、CPMP三个证书该如何选择,有什么区别,哪个对于工作上的
  18. easyEcharts3.5移动端echarts,折线,雷达,柱状,地图,饼图,温度计,水球纯js绘制canvas渲染
  19. ArchLinux 安装导航
  20. ADV流速仪坐标系统

热门文章

  1. html程序国庆节祝福,2018最新的国庆节祝福语
  2. python牛顿法解非线性方程组_萌新请教牛顿法求解三元非线性方程组
  3. 【C语言】强迫症是不是病QAQ
  4. java复习系列[2] - Java多线程
  5. linux自动重启电脑脚本,linux下通过脚本实现自动重启程序的方法
  6. eclipse ssh mysql_Eclipse 配置SSH 详解
  7. Flask 学习 (二) blueprint 示例
  8. YYH算组合数(NOIP模拟赛Round 6)
  9. MySql单表的curd-02
  10. 记一次使用Dapper 进行的数据迁移和清洗工作