1. env: java 11 + IntelliJ IDEA 2021.3.2 (Community Edition)
2. file->new project->Maven:

pom.xml 需要导入的包:后面三个是jdk8升级到11后,可能会出错,需要用到的包
org.springframework.boot spring-boot-starter-parent 1.2.6.RELEASE org.springframework.boot spring-boot-starter-web javax.xml.bind jaxb-api 2.3.1 javax.activation activation 1.1.1 org.springframework.boot spring-boot-starter-thymeleaf
3.编写MainApplication.java 作为启动类
@SpringBootApplication
//@ComponentScan(basePackages= "com/example/controller") 如果controller和启动类不再一个包下则需要使用组件扫描标签用于寻找,或者WhitePage error
public class MainApplication {
public static void main(String[] args){
SpringApplication.run(MainApplication.class, args);
}
}
4.编写controller类:
@RestController
public class HelloController {
@ResponseBody
@RequestMapping("/hello")
public String HelloController(){
return "Hello this is hello handler 02";
}
}
5.run main(), 测试访问地址:
6. application.properties可配置端口等信息
spring.freemarker.checkTemplateLocation=false server.port=8888
7.打包:
org.springframework.boot spring-boot-starter-parent 1.2.6.RELEASE

cmd: jave -jar xxx.jar