SpringBoot学习笔记一 | 快速入门

一、简介

Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是用来简化新 Spring 应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。

springboot的特点

创建独立的 Spring 应用程序
嵌入的 Tomcat,无需部署 WAR 文件
简化 Maven 配置
自动配置 Spring
提供生产就绪型功能,如指标,健康检查和外部配置
开箱即用,没有代码生成,也无需 XML 配置。

二、构建工程

本教程使用IDEA作为开发工具,maven作为项目管理工具。
创建一个maven工程,目录结构如下


SpringBoot学习笔记一 | 快速入门_第1张图片
image.png

pom依赖


      
    
        org.springframework.boot
        spring-boot-starter-parent
        2.0.0.RELEASE
         
    
    
      
        
            org.springframework.boot
            spring-boot-starter-web
        
    

其中spring-boot-starter-web不仅包含spring-boot-starter,还自动开启了web功能。
新建一个Controller

package com.yjj.sbfirst.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {
    @RequestMapping("/")
    public String index(){
        return "hello springboot";
    }
}

新建启动类,此类需在其他类的父包,我的在com.yjj包下,其他类则在com.yjj.controller或com.yjj.service等等

public class App{
    public static void main(String[] args) {
        SpringApplication.run(App.class,args);
    }
}

SpringBoot的启动方式不再手动启动Tomcat 而是run App启动类,然后访问localhost:8080/ 如下:


SpringBoot学习笔记一 | 快速入门_第2张图片
image.png

三、神奇之处

  • 我们没有配置web.xml
  • 我们没有配置任何的springmvc配置,springboot帮我们做了
  • 我们没有配置Tomcat,springboot内嵌Tomcat

你可能感兴趣的:(SpringBoot学习笔记一 | 快速入门)