(1)IDEA环境搭建

  • Spring Initializr

image.png

  • 选择Spring Web

image.png

  • 目录结构

image.png

(2)Hello World

  • 入口类Application ```java package com.monkey.springdemo;

import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication public class SpringdemoApplication {

  1. public static void main(String[] args) {
  2. SpringApplication.run(SpringdemoApplication.class, args);
  3. }

}

  1. - 新建一个Controller
  2. ```java
  3. package com.monkey.springdemo.controller;
  4. import org.slf4j.Logger;
  5. import org.slf4j.LoggerFactory;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7. import org.springframework.web.bind.annotation.RestController;
  8. @RestController
  9. public class HelloController {
  10. private static final Logger logger = LoggerFactory.getLogger(HelloController.class);
  11. @RequestMapping("/index")
  12. public String index() {
  13. logger.info("你好");
  14. return "Hello World";
  15. }
  16. }

image.png

(3)打包Jar

  • 生成jar文件

image.png

  • 部署服务
    1. java -jar springdemo-0.0.1-SNAPSHOT.jar