一、搭建基础环境
1、java环境的搭建
2、maven的安装,下载maven,解压缩,在windows环境变量中配置maven的bin目录
二、开发工具
1、下载spring的sts开发工具,并安装
三、demo的创建
1、打开https://start.spring.io/,制作一个web的demo
2、用sts工具打开该项目,sts会根据maven获取依赖的库,这个过程可能需要点时间,如果失败,在工程中可能无法创建java类,会提示不是java项目,如果这样可以再右键项目-》maven-》update project..一下
3、删除com.example下的.java文件,重新创建一个Application的java类,内容如下
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication //=@ComponentScan+ @EnableAutoConfiguration+ @Configuration
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
4、创建一个com.example.web的包,创建一个DefaultController.java文件,内容如下
package com.example.web;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class DefaultController {
@RequestMapping("/")
String home() {
return "Hello World!";
}
}
5、项目右键-》run as-》spring boot app,ok,在浏览器里访问就可以了。