欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Spring Boot学习笔记

程序员文章站 2022-07-10 18:10:58
...

一、Spring Boot入门

1.Spring Boot简介

  • 主要作用:简化Spring的开发,免去了SpringMVC各种配置文件的繁琐,并且部署项目不需要打成war

2.微服务

  • 2014,Martin Fowler

  • 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.环境准备

1.IDEA

2.maven

4.Spring Boot HelloWorld

1.新建maven项目

2.配置pom.xml,导入Spring Boot相关依赖

3.编写main函数,用来启动SpringBootApplication

/**
 *@SpringBootApplication 标注此函数是一个SpringBootApplication
 * */
@SpringBootApplication
public class HelloSpringBoot {
    public static void main(String[] args) {
        SpringApplication.run(HelloSpringBoot.class,args);

    }
}

4.编写Contorller

@Controller
public class HelloController {

    @ResponseBody
    @RequestMapping("/hello")
    public String hello(){
        return "Hello World!";
    }

}

5.运行 main

​ 浏览器中输入http://localhost:8080/hello ,浏览器即可得到response(“Hello World!”)

6.将项目打成jar包,如下

Spring Boot学习笔记

7.一键部署

Spring Boot学习笔记