Spring Boot: first demo

  1. 生成Spring boot工程:https://start.spring.io/

    Spring Boot: first demo_第1张图片
    image.png

  2. Deme(返回字符串、json串、配置server.port)

@Controller
@SpringBootApplication
public class Springbootlesson1Application {
    @RequestMapping("/")
    @ResponseBody
    String home(){
        return "Hello World!";
    }
    @RequestMapping("/rest")
    @ResponseBody
    Map rest(){
        Map ret = new HashMap<>();
        ret.put("1", "A");
        ret.put("2", 2);
        return ret;
    }
    public static void main(String[] args) {
        SpringApplication.run(Springbootlesson1Application.class, args);
    }
}
#application.properties
server.port=7001
Spring Boot: first demo_第2张图片
启动日志

Spring Boot: first demo_第3张图片
image.png

Spring Boot: first demo_第4张图片
image.png
  1. 配置management.port
#application.properties
management.port=8001
# pom.xml

    org.springframework.boot
    spring-boot-starter-actuator

Spring Boot: first demo_第5张图片
image.png

Spring Boot: first demo_第6张图片
image.png

Spring Boot: first demo_第7张图片
image.png

Spring Boot: first demo_第8张图片
jconsole

Spring Boot: first demo_第9张图片
image.png

Spring Boot: first demo_第10张图片
image.png

你可能感兴趣的:(Spring Boot: first demo)