Springboot教程:Templates模板入门

不久之前,随着libraries (库)数量及其依赖关系的指数增长,依赖关系管理变得非常复杂,需要大量的技术专业知识才能正确完成。通过引入springboot starter templates,之后如果要在项目中使用任何流行的库,就可以从使用的正确依赖项方面下手。

Spring Boot附带了50多个不同的入门模块,为许多不同的框架提供了现成的集成库,例如和NoSQL的数据库连接,Web服务,社交网络集成,监控库,日志记录,模板渲染,列表一直在持续更新。

starter template如何工作?

Spring Boot starter templates是包含启动特定功能所需的所有相关传递依赖关系的集合的模板。每个启动器都有一个特殊文件,其中包含Spring提供的所有依赖项的列表。

这些文件可以在/resources/META-INF  templates 项目的文件夹中找到,文件名是spring.provides

例如

spring-boot-starter-data-jpa  启动模板的提供文件,点这里:github

文件内容是:

1
provides: spring-orm, hibernate-entity-manager, spring-data-jpa

这告诉我们,通过spring-boot-starter-data-jpa在我们的构建中作为依赖项,我们将自动获取spring-ormhibernate-entity-managerspring-data-jpa。这些库将为我们提供开始编写JPA / DAO代码的所有基本功能。

因此,下次当您想要为项目提供任何特定功能时,我建议您检查现有的入门模板,看看是否可以直接使用它。并且社区很火热,这个列表还在继续在增长,您也可以为它做出贡献。

流行的Templates模板及其依赖项

我列出了一些非常频繁使用的spring starters 以及它们带来的依赖关系,仅供参考。

STARTER DEPENDENCIES
spring-boot-starter spring-boot, spring-context, spring-beans
spring-boot-starter-jersey jersey-container-servlet-core, jersey-container-servlet, jersey-server
spring-boot-starter-actuator spring-boot-actuator, micrometer-core
spring-boot-starter-aop spring-aop, aspectjrt, aspectjweaver
spring-boot-starter-data-rest spring-hateoas, spring-data-rest-webmvc
spring-boot-starter-hateoas spring-hateoas
spring-boot-starter-logging logback-classic, jcl-over-slf4j, jul-to-slf4j
spring-boot-starter-log4j2 log4j2, log4j-slf4j-impl
spring-boot-starter-security spring-security-web, spring-security-config
spring-boot-starter-test spring-test, spring-boot,junit,mockito, hamcrest-library, assertj, jsonassert, json-path
spring-boot-starter-web-services spring-ws-core

 

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

关注我们