文章目录


 

前言

Spring Boot它简化了很多繁琐的配置,利用Starter组件可以快速搭建一个项目的脚手架。

(原理图如下 采用自JavaSchool)

一、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>

二、两种依赖(POM文件中)

1.spring- boot- starter-xxx(官方)

2.xxx- Spring-boot- starter(非官方)

xxx就是我们想要依赖的组件或jar包,通常会用来引入thymeleaf引擎和my batis框架所配置的依赖,但引入之后还需要约定配置才可以正常使用。
spring:
  thymeleaf:
    enabled: true
    servlet:
      content-type: text/html
    mode: HTML
    ## 前缀
    prefix: classpath:/templates/
    ## 后缀
    suffix: .html

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


总结

1•Starter封装了所有需要的依赖,避免我们自行添加导致的jar包冲突

2•Starter使开发者不需要关注各种依赖库的处理,不需要具体配置信息,会由Spring Boot自动通过class path路径下的类发现并加载需要的bean。

简言之,starter就是一个依赖传递包(依赖引入,自动配置)。


版权声明:本文为m0_67361769原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/m0_67361769/article/details/124109978