如何基于Spring Boot搭建一个完整的项目

本文详细介绍了如何基于Spring Boot搭建一个完整的项目,包括Spring Boot的特点、启动器、内嵌Web容器、自动配置、项目结构、模块包目录、Mybatis集成以及日志框架的使用。通过实例解析了Spring Boot如何简化开发流程,让开发者能够快速上手。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

使用Spring Boot做后台项目开发也快半年了,由于之前有过基于Spring开发的项目经验,相比之下觉得Spring Boot就是天堂,开箱即用来形容是绝不为过的。在没有接触Spring Boot 之前,以为Spring Boot 是一个新的框架体系。正好Spring Boot出现先的时候,也是微服务特别火的时候,大家不约而同把Spring Boot 和微服务等同起来了,但其实并不是如此,那么到底什么是Spring Boot ? 基于Spring Boot 又是如何开发的呢 ? 带着这两个问题,大家继续往下看。

Spring Boot 特点

Our primary goals are:

  1. Provide a radically faster and widely accessible getting started experience for all Spring development.
  2. Be opinionated out of the box, but get out of the way quickly as requirements start to diverge from the defaults.
  3. Absolutely no code generation and no requirement for XML configuration.

上述是从Spring Boot官方文档上摘录的,简述言之Spring Boot框架的目的就是开箱即用、去除配置。Spring Boot并不是重复去造就一个轮子,它的出现是为Spring的开发带来一种全新的体验,从而大大的降低Spring框架的使用门槛。

下面主要从几个特性介绍Spring Boot是如何简化开发的。

Spring Boot启动器

使用过Spring Boot的同学都知道,快速编写一个Spring Boot的Web Demo需要在pom文件中加入如下:

 <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

Spring Boot 提供了很多像spring-boot-starter-web这样的启动器,名称都是spring-boot-starter-* 。

这里写图片描述

截图部分来自Spring Boot官网,只是Spring Boot启动器中小部分,更多启动器可以到官网上查找。

启动器为何物? 以spring-boot-starter-web 这个web开发用到的启动器为例。

这里写图片描述

从上图可以看出spring-boot-starter-web.jar包里面没有任何代码,对没有任何代码。只有一个pom文件。what ? 其中包中pom.xml的内容如下所示:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
    </dependency>
</dependencies>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值