已經來實習了一段時間了,從開始接觸到SpringBoot框架到如今一直都感受SpringBoot框架實在是爲咱們帶來了巨大遍歷之處,以前一直在用並無總結一下,如今有空從零開始寫點東西,也算是對基礎的鞏固吧..web
一,環境準備spring
1.推薦使用IntelliJ IDEA,用過都知道好。tomcat
2.mavenmybatis
二,創建新項目mvc
打開IDEA創建一個新的Maven項目,這個很簡單不在解釋了。框架
而後咱們打開咱們的pom文件添加SpringBoot的相關依賴和插件。maven
首先設置咱們的<parent>分佈式
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.2.RELEASE</version>//這裏的版本能夠按本身須要更改 </parent>
而後設置咱們最基本的SpringBoot應用web依賴。spring-boot
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> //因爲繼承了partent不須要再指定version </dependency>
須要說明的是spring-boot-starter-web除了彙集了SpringBoot自動配置的一些jar包還包含了基本的Spring的jar包,spring-aop,spring-beans,spring-context,spring-webmvc,spring-boot-start-tomcat等等jar包。spa
正是有內置的tomcat,咱們的SpringBoot應用才能達成jar包直接運行,這樣的特性很利於咱們分佈式應用的部署,部署攜帶都很方便。
如今一個最基本的SpringBoot應用環境已經搭建完成,接下來咱們編寫相應的controller.
三,編寫代碼
代碼很簡單,可是須要注意的一點是SpringApplication啓動類必須放在一個包下,不然會報錯,我的以爲是由於SpringBoot自動啓動默認類下包掃描若是沒有包的話確定不行啊。
@SpringBootApplication //這個註解等同於 //@configuration(新版@SpringBootConfiguration) //@componentScan //@enableAutoConfiguration public class MySpringBootApplication { public static void main(String[] args) { SpringApplication.run(MySpringBootApplication.class, args); } }
直接運行便可看到SpringBoot的啓動標識。。。
下一章我會寫一個SpringBoot應用配合mybatis框架的簡單數據訪問應用,並打包爲jar包部署運行。。