Spring Boot 四大核心组件,你知道几个呢?

本文详细介绍了Spring Boot的四大核心组件:Starter、Autoconfigure、CLI和Actuator。Starter简化了依赖管理和Bean注入,Autoconfigure实现了自动配置Bean,CLI提供了命令行工具,Actuator则提供了生产级别的监控功能。通过对这些组件的理解,可以更好地掌握Spring Boot的使用。
摘要由CSDN通过智能技术生成

前言

先透露一下,四大组件分别是:starter, autoconfigure, CLI 以及actuator。下面我们就来详细介绍一些他们有什么用。

一、Spring Boot Starter

1.1 Starter的应用示例

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

<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.3.2</version>
</dependency>

 

Spring Boot 基础就不介绍了,推荐下这个实战教程:

https://github.com/javastacks/spring-boot-best-practice

在我们的Spring Boot项目种的POM文件中总会看到这两种依赖:

spring-boot-starter-xxx 和 xxx-spring-boot-starter

这就是spring boot的四大组件之一的starter。

a、spring-boot-starter-thymeleaf

 b、mybatis-spring-boot-starter

 

两种starter的区别就是 >>

  • 官方提供的starter是这样的:spring-boot-starter-xxx
  • 非官方的starter是这样的:xxx-spring-boot-starter

其中xxx就是我们想要依赖的组件或者jar包。上例就是我们spring boot用来引入thymeleaf引擎和mybatis框架所配置的依赖。引入之后通过简单的约定配置就可以正常使用。比如:

Thymeleaf引擎约定配置:

##前端引擎配置
spring:
  thymeleaf:
    enabled: true
    servlet:
      content-type: text/html
    mode: HTML
    ## 页面前缀
    prefix: classpath:/templates/
    ## 后缀
    suffix: .html

Mybatis约定配置:

mybatis:
  mapper-locations: classpath:mapper/*.xml  #注意:一定要对应mapper映射xml文件的所在路径
  type-aliases-package: com.hi.ld.vo.system  # 注意:对应实体类的路径
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

下面让我们来看看以前怎么配置thymeleaf。

1.2 Spring Boot之前的Thymeleaf和Mybatis应用

废话不多说,直接上代码:

1.2.1 Thymeleaf配置

a. 添加对应依赖:


                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值