SpringBoot快速入门

从使用Maven零搭建一个SpringBoot项目

  1. 创建maven工程

    无需勾选 archetype,直接点击下一步即可

    输入坐标,项目名点击下一步,完成后选择AutoImport即可

     

  2. 添加SpringBoot依赖

    这里只是对父工的引用,没有实际的引用,但是做了版本的声明,在加入依赖后无需指定版

    <parent>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-parent</artifactId>
           <version>2.1.3.RELEASE</version>
       </parent>
  3. 添加SpringBoot启动器依赖

    <dependencies>
           <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-web</artifactId>
           </dependency>
       </dependencies>
    添加启动器后 web工程常用的依赖会自动帮你引入
  4. 编写启动类

    packagecn.rayfoo;

    importorg.springframework.boot.SpringApplication;
    importorg.springframework.boot.autoconfigure.SpringBootApplication;

    @SpringBootApplication
    publicclassApplication{
       publicstaticvoidmain(String[] args) {
           SpringApplication.run(Application.class);
      }
    }
  5. 编写Controller直接访问

    packagecn.rayfoo.web;

    importorg.springframework.web.bind.annotation.RequestMapping;
    importorg.springframework.web.bind.annotation.RestController;

    @RestController
    publicclassUserController{

       @RequestMapping("/findOne")
       publicStringgetOne(){
           return"ok";
      }

    }
  6. 配置SpringBoot热部署

             <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-devtools</artifactId>
    </dependency>

补充:如果遇到run启动非常缓慢解决方法如下:

1.在命令行中输入hostname 查询当前主机名称 2.到C盘Windows\System32\drivers\etc中找到host文件 3.复制一份其它地方进行编辑,编辑时在hostname之后添加.local 4.注意事项: 127.0.0.1和local之间是两个tab 不是空格

posted @ 2019-11-07 17:04  张瑞丰  阅读(119)  评论(0编辑  收藏  举报