传统的web开发都是须要将开发好的web项目部署到服务器(通常是tomcat或者是其余的服务器),可是有了SpringBoot以后这些重复繁琐的工做咱们就没必要要再作这些重复繁琐的工做了,由于SpringBoot内嵌了web容器(tomcat/jetty),再编写完成项目以后能够快速便捷启动项目,进行项目的调试。web
使用SpringBoot作web开发须要以下几个步骤:spring
1.新建一个maven项目tomcat
2.早maven的pom文件导入依赖(其中test依赖不必定须要)服务器
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
3.编写启动类(此处须要@SpringBootApplication注解)app
@SpringBootApplication
public class MicroserviceApplication {
public static void main(String[] args) {
SpringApplication.run(MicroserviceApplication.class, args);
}
}
4.编写配置文件,能够是properties或者是yml(这个层次结构更加清晰,推荐使用)maven
server:
port: 8081
5.编写请求接口或者静态文件spring-boot
@RestController public class TestController { @RequestMapping("/request/getData") public Object getData(){ return "data"; } }
请求成功!!spa