美文网首页
SpringBoot学习笔记一 | 快速入门

SpringBoot学习笔记一 | 快速入门

作者: 殷俊杰 | 来源:发表于2018-03-17 21:34 被阅读0次

一、简介

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

springboot的特点

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

二、构建工程

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


image.png

pom依赖


    <!--  
       spring boot 父节点依赖,  
       引入这个之后相关的引入就不需要添加version配置,  
       spring boot会自动选择最合适的版本进行添加。  
     -->  
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <dependencies>
      
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

其中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/ 如下:


image.png

三、神奇之处

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

相关文章

网友评论

      本文标题:SpringBoot学习笔记一 | 快速入门

      本文链接:https://www.haomeiwen.com/subject/jjsoyxtx.html