第二章 微服务构建:Spring Boot
- 如何构建Spring Boot项目
- 如何实现RESTful API接口
- 如何实现多环境的Spring Boot应用配置
- 深入理解Spring Boot配置的启动机制
- Spring Boot应用的监控与管理
框架简介
快速入门
项目构建与解析
- java 7 及以上版本
- Spring framework 4.2.7及以上版本
- Maven 3.2 及以上版本 / Gradle 1.12 及以上版本
- 通过官方的Spring Initializr工具来产生基础项目
- 访问 http://start.spring.io

- 选择构建工具 Maven Project、Spring boot版本选择1.3.7以上,填写Group和Artifact信息,在Search for dependencies 中搜索需要的其他依赖包,因为要实现RESTful API,所以可以添加Web依赖。
- 单击Generate Project按钮下载项目压缩包
- 解压项目包,并用IDE以Maven项目导入。
工程结构解析

- src/main/java: 主程序入口HelloApplication,可通过该类直接启动Spring Boot项目
- src/main/resources:配置目录,引入配置信息。由于引入了Web模块,因此产生了static目录和templates目录,前者存放静态资源,如图片、CSS、javascript等;后者用于存放Web页面的模板文件
- src/test:单元测试目录,生成的HelloApplicationTests通过JUnit4实现,可以直接用运行Spring Boot应用的测试。
Maven配置分析
<?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>com.example</groupId>
<artifactId>hello</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>hello</name>
<description>Demo project for Spring Boot</description> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<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-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
实现RESTful API
@RestController
public class HelloController { @RequestMapping(value = "index")
public String index(){
return "hello";
}
}
启动Spring Boot应用
配置详解
配置文件
server:
port: 9996
contextPath: /webux
tomcat:
uri-encoding: utf-8
spring:
application:
name: emer-business-webux
thymeleaf:
cache: false
suffix: .html
content-type: text/html; charset=utf-8
enabled: true
encoding: utf-8
通过YAML的配置方式可以减少配置内容的字符量,其结构也更为清晰易读。
自定义参数
第二章 微服务构建:Spring Boot的更多相关文章
- 构建微服务:Spring boot
构建微服务:Spring boot 在上篇文章构建微服务:Spring boot 提高篇中简单介绍了一下spring data jpa的基础性使用,这篇文章将更加全面的介绍spring data jp ...
- Spring boot学习1 构建微服务:Spring boot 入门篇
Spring boot学习1 构建微服务:Spring boot 入门篇 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框 ...
- 微服务下 Spring Boot Maven 工程依赖关系管理
单体 Spring Boot Maven 工程 最基本的 pom.xml 包含工程信息.Spring Boot 父工程.属性配置.依赖包.构建插件 <?xml version="1.0 ...
- SpringCloud(8)微服务监控Spring Boot Admin
1.简介 Spring Boot Admin 是一个管理和监控Spring Boot 应用程序的开源软件.Spring Boot Admin 分为 Server 端和 Client 端,Spring ...
- 构建微服务:Spring boot 入门篇
什么是Spring Boot Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是用来简化新 Spring 应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而 ...
- Java微服务之Spring Boot on Docker
本文学习前提:Java, Spring Boot, Docker, Spring Cloud 一.准备工作 1.1 安装Docker环境 这一部分请参考我的另一篇文章<ASP.NET Core ...
- spring boot 2.0.3+spring cloud (Finchley)8、微服务监控Spring Boot Admin
参考:Spring Boot Admin 2.0 上手 Spring Boot Admin 用于管理和监控一个或多个Spring Boot程序,在 Spring Boot Actuator 的基础上提 ...
- 小马哥-Java 微服务实践 - Spring Boot 系列-01Java 微服务实践 - Spring Boot 系列(一)初体验
课程github地址 https://github.com/mercyblitz/segmentfault-lessons 传统的web应用架构.微服务是一种架构.不限定什么语言 单体应用和微服务的对 ...
- 第二章 微服务网关基础组件 - zuul入门
一.zuul简介 1.作用 zuul使用一系列的filter实现以下功能 认证和安全 - 对每一个resource进行身份认证 追踪和监控 - 实时观察后端微服务的TPS.响应时间,失败数量等准确的信 ...
随机推荐
- 100-days: eleven
Title: Facebook's live streaming(网络直播) is criticized(批评) after mosque(清真寺) shooting(枪击). live adj.现场 ...
- PCIe 驱动流程(LTSSM)
本次的工作是完成刚流片的FPGA中PCIe IP核的bring up,也就是芯片的中PCIe的第一个使用者,将PCIe IP核正常使用起来,并配合公司的EDA团队,完成PCIe IP核到用户的呈现. ...
- 106. Construct Binary Tree from Inorder and Postorder Traversal根据后中序数组恢复出原来的树
[抄题]: Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assum ...
- 560. Subarray Sum Equals K 求和为k的子数组个数
[抄题]: Given an array of integers and an integer k, you need to find the total number of continuous s ...
- [leetcode]45. Jump Game II青蛙跳(跳到终点最小步数)
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- React-router4 第七篇 Recursive Paths 递归路径
https://reacttraining.com/react-router/web/example/recursive-paths import React from 'react' import ...
- 杨其菊201771010134《面向对象程序设计(java)》第六周学习总结
<面向对象程序设计(java)>第六周学习总结 第一部分:理论知识 1)类.超类和子类2)Object:所有类的超类 3)泛型数组列表4)对象包装器和自动打包 5)参数数量可变的方法 6) ...
- 11.5 vmstat:虚拟内存统计
vmstat vmstat是Virtual Memory Statistics(虚拟内存统计)的缩写,利用vmstat命令可以对操作系统的内存信息.进程状态和CPU活动等进行监视.但是只能对系统的整体 ...
- 基于UML的毕业选题系统建模研究
一.基本信息 标题:基于UML的毕业选题系统建模研究 时间:2018 出版源:电脑迷 领域分类:UML建模技术 二.研究背景 问题定义:为了加强学生设计分析开发软件的相关能力,有效避免结构化模型存在的 ...
- Codeforces Round #512 (Div. 2) D. Vasya and Triangle
参考了别人的思路:https://blog.csdn.net/qq_41608020/article/details/82827632 http://www.cnblogs.com/qywhy/p/9 ...