1.1 长处:

简化spring开发/约定优于配置 :

  • 嵌入式的servlet容器;
  • starter主动依赖和版本控制;
  • 大量主动配置, 简化开发;
  • 无需配置xml, 无代码生成, 开箱即用;
  • 利用监控:准生产环境的运行时利用监控;

1.2 毛病:

入门容易, 精通难~

1.3 微服务

springboot:

一个利用, 是一组小型服务, 能够通过http形式进行互通; 每一个性能元素都是一个能够独立替换和独立降级的单元;

springcloud:

整个利用的大型分布式网格之间的调用;

1.4 helloworld

1.4.1 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.niewj</groupId>    <artifactId>springboot-study</artifactId>    <version>1.0-SNAPSHOT</version>    <properties>        <spring-boot-version>2.3.2.RELEASE</spring-boot-version>    </properties>    <modules>        <module>springboot-01-helloworld</module>    </modules>    <!-- 示意是一个pom总的父工程 -->    <packaging>pom</packaging>    <dependencies>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-parent</artifactId>            <version>${spring-boot-version}</version>        </dependency>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-web</artifactId>            <version>${spring-boot-version}</version>        </dependency>    </dependencies></project>

1.4.2 类文件:

SpringBootApplication 启动类

package com.niewj.springboot;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;/** * Created by niewj on 2020/8/4 18:04 */@SpringBootApplicationpublic class HelloApplication {    public static void main(String[] args) {        SpringApplication.run(HelloApplication.class, args);    }}

HelloController.java

package com.niewj.springboot.controller;import com.niewj.springboot.model.User;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;/** * Created by niewj on 2020/8/4 18:08 */@Controllerpublic class HelloController {    @RequestMapping("/hello")    @ResponseBody    public Object hello(){        return new User("niewj", 33);    }}

User实体类:

package com.niewj.springboot.model;/** * Created by niewj on 2020/8/4 18:09 */public class User {    private String name;    private int age;    public User(String name, int age) {        this.name = name;        this.age = age;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public int getAge() {        return age;    }    public void setAge(int age) {        this.age = age;    }}

完结; 拜访: http://localhost:8080/hello

返回:

{"name":"niewj","age":33}