@SpringBootApplication
package com.ch.boot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; /**主程序类
* @SpringBootApplication:这是一个SpringBoot应用
*/
@SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class,args); }
}
HelloController
package com.ch.boot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; @ResponseBody
@Controller
@RestController
public class HelloController { @RequestMapping("/hello")
public String handle01(){
return "Hello,SpringBoot2!!"; } }

配置文件

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>com.ch</groupId>
<artifactId>helloSpringBootM</artifactId>
<version>1.0-SNAPSHOT</version> <properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
</parent> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependencies>
</project>

为什么用SpringBoot

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".

能快速创建出生产级别的Spring应用

2.1、SpringBoot优点

  • Create stand-alone Spring applications
  • 创建独立Spring应用
  • Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
  • 内嵌web服务器
  • Provide opinionated 'starter' dependencies to simplify your build configuration
  • 自动starter依赖,简化构建配置
  • Automatically configure Spring and 3rd party libraries whenever possible
  • 自动配置Spring以及第三方功能
  • Provide production-ready features such as metrics, health checks, and externalized configuration
  • 提供生产级别的监控、健康检查及外部化配置
  • Absolutely no code generation and no requirement for XML configuration
  • 无代码生成、无需编写XML

SpringBoot是整合Spring技术栈的一站式框架

SpringBoot是简化Spring技术栈的快速开发脚手架

2.2、SpringBoot缺点

  • 人称版本帝,迭代快,需要时刻关注变化
  • 封装太深,内部原理复杂,不容易精通

3、时代背景

3.1、微服务

James Lewis and Martin Fowler (2014) 提出微服务完整概念。https://martinfowler.com/microservices/

In short, the microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery. There is a bare minimum of centralized management of these services, which may be written in different programming languages and use different data storage technologies.-- James Lewis and Martin Fowler (2014)

  • 微服务是一种架构风格
  • 一个应用拆分为一组小型服务
  • 每个服务运行在自己的进程内,也就是可独立部署和升级
  • 服务之间使用轻量级HTTP交互
  • 服务围绕业务功能拆分
  • 可以由全自动部署机制独立部署
  • 去中心化,服务自治。服务可以使用不同的语言、不同的存储技术

3.2、分布式

分布式的困难

  • 远程调用
  • 服务发现
  • 负载均衡
  • 服务容错
  • 配置管理
  • 服务监控
  • 链路追踪
  • 日志管理
  • 任务调度
  • ......

分布式的解决

  • SpringBoot + SpringCloud

3.3、云原生

原生应用如何上云。 Cloud Native

上云的困难

  • 服务自愈
  • 弹性伸缩
  • 服务隔离
  • 自动化部署
  • 灰度发布
  • 流量治理
  • ......

上云的解决

4、如何学习SpringBoot

4.1、官网文档架构

查看版本新特性;

https://github.com/spring-projects/spring-boot/wiki#release-notes

SpringBoot2入门

1、系统要求

  • Java 8 & 兼容java14 .
  • Maven 3.3+
  • idea 2019.1.2

1.1、maven设置

<mirrors>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors> <profiles>
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
</profiles>

2、HelloWorld

需求:浏览发送/hello请求,响应 Hello,Spring Boot 2

2.1、创建maven工程

2.2、引入依赖

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
</parent> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependencies>

2.3、创建主程序

/**
* 主程序类
* @SpringBootApplication:这是一个SpringBoot应用
*/
@SpringBootApplication
public class MainApplication { public static void main(String[] args) {
SpringApplication.run(MainApplication.class,args);
}
}

2.4、编写业务

@RestController
public class HelloController { @RequestMapping("/hello")
public String handle01(){
return "Hello, Spring Boot 2!";
} }

2.5、测试

直接运行main方法

2.6、简化配置

application.properties

server.port=8888

2.7、简化部署

 <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

把项目打成jar包,直接在目标服务器执行即可。

注意点:

  • 取消掉cmd的快速编辑模式

第一个helloworld,有点小兴奋的更多相关文章

  1. 微信小程序开发入门:10分钟从0开始写一个hello-world

    小程序开发需要三个描述整体程序的app文件 和 一个描述多个页面的 pages文件夹. (1)三个app文件分别是app.js,app.json,app.wxss. app.js文件是脚本文件处理一些 ...

  2. zynq学习01 新建一个Helloworld工程

    1,好早买了块FPGA板,zynq 7010 .终极目标是完成相机图像采集及处理.一个Window C++程序猿才开始学FPGA,一个小菜鸟,准备转行. 2,关于这块板,卖家的官方资料学起来没劲.推荐 ...

  3. 学习spring2--跟我一起学Spring 3(3)–使用Spring开发第一个HelloWorld应用

    http://www.importnew.com/13246.html     首页 所有文章 资讯 Web 架构 基础技术 书籍 教程 我要投稿 更多频道 » - 导航条 - 首页 所有文章 资讯 ...

  4. 字节码编程,Byte-buddy篇一《基于Byte Buddy语法创建的第一个HelloWorld》

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 相对于小傅哥之前编写的字节码编程: ASM.Javassist 系列,Byte Bu ...

  5. 第一个Mac shell 小脚本

    大多数程序员都喜欢偷懒的,我也不例外.相信好多Android开发的coder 在网络http请求方面,会浪费很多时间在接口调试这里..有时候,自己写了一个小测试,行还好,不行的话,还要跟写后台的哥们一 ...

  6. Android Studio新建一个HelloWorld 程序(App)

    Android Studio新建一个HelloWorld程序(App) 新建 或者直接启动程序(注:如果已有程序,此方法会直接打开最近一次关闭从程序) 更改App名 选择App运行平台 选择模板 更改 ...

  7. [浅学] 1、Node.js尝试_安装&运行第一个helloworld

    官网:https://nodejs.org/ 介绍:Node.js® is a platform built on Chrome's JavaScript runtime for easily bui ...

  8. 2.每人自己建立一个HelloWorld项目,练习使用git的add/commit/push/pull/fetch/clone等基本命令。比较项目的新旧版本的差别。答题人:张立鹏

    第1步:创建SSH Key.在用户主目录下,看看有没有.ssh目录,如果有,再看看这个目录下有没有id_rsa和id_rsa.pub这两个文件,如果已经有了,可直接跳到下一步.如果没有,打开Shell ...

  9. 第二章——建立一个HelloWorld项目,练习使用git的add/commit/push/pull/fetch/clone等基本命令。比较项目的新旧版本的差别-----答题者:徐潇瑞

    1.首先下载安装git,很简单所以就不详细说了,当弹出一个类似的命令窗口的东西,就说明Git安装成功 2.因为Git是分布式版本控制系统,所以需要填写用户名和邮箱作为一个标识 3.接着,注册githu ...

  10. 一个python爬虫小程序

    起因 深夜忽然想下载一点电子书来扩充一下kindle,就想起来python学得太浅,什么“装饰器”啊.“多线程”啊都没有学到. 想到廖雪峰大神的python教程很经典.很著名.就想找找有木有pdf版的 ...

随机推荐

  1. 快速量产低功耗 4G 定位方案?Air201 模组来搞定!

    今天我们来了解的是Air201模组快速量产低功耗 4G 定位方案,希望大家有所收获. 寻寻觅觅低功耗4G定位方案? 一个Air201就够了! --定位准.体积小.功耗低,助力行业客户快速量产! 01 ...

  2. Solon MVC 的 @Mapping 用法说明

    在 Solon Mvc 里,@Mapping 注解一般是配合 @Controller 和 @Remoting,作请求路径映射用的.且,只支持加在 public 函数 或 类上. 1.注解属性 属性 说 ...

  3. apache做负载均衡器 配置

    将Apache作为LoadBalance前置机分别有三种不同的部署方式,分别是: 1 )轮询均衡策略的配置 进入Apache的conf目录,打开httpd.conf文件,在文件的末尾加入: Proxy ...

  4. 2020-2021 ACM-ICPC Brazil Subregional Programming Contest

    A. Sticker Album 你想要得到\(n\)张贴纸,每包礼物中等概率出现 \([A,B]\)范围内数量的贴纸,求需要买多少包礼物才能至少获得\(n\)张贴纸的期望次数 \(1 \leq n ...

  5. OAuth2 当前登录用户修改

    1.业务说明 有些情况下,我们希望用户登录后,可以修改用户的某些信息,比如修改当前的公司信息. 2.实现方法 @Resource TokenStore tokenStore; public JsonR ...

  6. Vue 二维码组件

    1.前言 该组件依赖qrcode.js与element-ui 支持二维码大小配置,点击大图预览 该组件以vue文件形式进行封装,需要配置httpVueLoader插件进行引入,其他格式请自行更改源码 ...

  7. u-chart

    1.前言 uni-app能用的图表插件太少,这是唯一能用,虽然官方声称 傻瓜式 配置,但是在我看来异常繁琐,可选的配置项一大堆统统堆到demo里面,导致上手非常困难.既然踩了坑,我就记录下来. 2.基 ...

  8. vite2+vue3使用tsx报错React is not defined、h is not defined

    vite 为 .jsx 和 .tsx 文件提供开箱即用支持. 如果不是在 react 中使用 jsx,对于报错: React is not defined 需要在 vite.config.js 文件中 ...

  9. CoFile 企业云盘大焕新啦!

    一.域名升级,更好记 俗话说的好,好记性不如字数少 cofile.net 指尖一敲,快乐来到 别拦着我,我就要用 CoFile 企业云盘 二.架构优化,不止更快 底层优化,加载提速,更快响应,加倍安全 ...

  10. FineReport模板性能问题排查方法

    1. 概述 模板的加载速度受到很多因素影响,如果一个模板预览的时候,加载较慢,该如何去分析问题原因呢? 2. 排查步骤 2.1 查看数据集查询速度 大部分模板加载慢,都是因为 sql 执行速度比较慢. ...