spring boot 它的設計目的就是爲例簡化開發,開啓了各類自動裝配,你不想寫各類配置文件,引入相關的依賴就能迅速搭建起一個web工程。它採用的是創建生產就緒的應用程序觀點,優先於配置的慣例。java
可能你有不少理由不放棄SSM,SSH,可是當你一旦使用了springboot ,你會以爲一切變得簡單了,配置變的簡單了、編碼變的簡單了,部署變的簡單了,感受本身大步流星,開發速度大大提升了。就比如,當你用了IDEA,你會以爲再也回不到Eclipse時代同樣。另,本系列教程所有用的IDEA做爲開發工具。web
你須要:spring
打開Idea-> new Project ->Spring Initializr ->填寫group、artifact ->鉤上web(開啓web功能)->點下一步就好了。apache
建立完工程,工程的目錄結構以下:瀏覽器
- src -main -java -package -SpringbootApplication -resouces - statics - templates - application.yml -test - pom
pom.xml的依賴:springboot
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.forezp</groupId> <artifactId>springboot-first-application</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>springboot-first-application</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <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> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
其中spring-boot-starter-web不只包含spring-boot-starter,還自動開啓了web功能。架構
說了這麼多,你可能還體會不到,舉個栗子,好比你引入了Thymeleaf的依賴,spring boot 就會自動幫你引入SpringTemplateEngine,當你引入了本身的SpringTemplateEngine,spring boot就不會幫你引入。它讓你專一於你的本身的業務開發,而不是各類配置。app
再舉個栗子,建個controller:maven
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RequestMapping; @RestController public class HelloController { @RequestMapping("/") public String index() { return "Greetings from Spring Boot!"; } }
啓動SpringbootFirstApplication的main方法,打開瀏覽器localhost:8080,瀏覽器顯示:分佈式
Greetings from Spring Boot!
Spring Cloud大型企業分佈式微服務雲架構源碼請加企鵝求求:一七九一七四三三八零