傳統的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