(1)IDEA环境搭建
- Spring Initializr
- 选择Spring Web
- 目录结构
(2)Hello World
- 入口类Application ```java package com.monkey.springdemo;
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication public class SpringdemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringdemoApplication.class, args);
}
}
- 新建一个Controller
```java
package com.monkey.springdemo.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
private static final Logger logger = LoggerFactory.getLogger(HelloController.class);
@RequestMapping("/index")
public String index() {
logger.info("你好");
return "Hello World";
}
}
(3)打包Jar
- 生成jar文件
- 部署服务
java -jar springdemo-0.0.1-SNAPSHOT.jar