第一章-spring boot快速入门hello world

一、spring boot 简介

  每一个spring boot 项目都是以spring的子项目的形式来运行,开发人员不用再去关注繁琐的配置文件,可以把精力放到业务逻辑以及更深层次的架构方面。

二、环境

  1. jdk1.8
  2. springboot 1.5.9.RELEASE
  3. apache maven(3.5.0)
  4. 开发工具(IntelliJ IDEA )

三、步骤

  1) 打开idea 选择file new projec

  

  2)找到Spring Initializr选中点击next。

  

  3)点击next

  

  4)入门项目只勾选web就可以,这里的标红版本为几个推荐版本会变化,后期我们自己在pom.xml中调整即可,点击next选择项目目录即可。

  

  5)找到pom文件并修改版本

修改前
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.13.BUILD-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

修改后

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

  6)项目结构简介

  

  7)编写hello world并运行,@RestController可以直接响应给前段,传统写法@Controller+@ResponseBody

  

  右击运行并访问,默认端口8080,chrome浏览器访问。

  

   

  8)打包运行,因为我们选择的是jar方式打包所以通过mvn clean package就可以打成jat包运行。

  

  也可maven projects打包更方便,根据需要可自行开启配置,找到target目录打开cmd命令行运行。

           

四、总结

   一个简单的spring boot hello world 程序就写好了。

  源码地址    https://github.com/binary-vi/binary.github.io/tree/master/SpringBoot-demo/demo01 

 

 

  

 

  

 

 

 

 

 




posted @ 2018-04-26 10:41  vi-2525  阅读(154)  评论(0编辑  收藏  举报