SpringBoot官方文档学习--创建你自己的启动器(starter)

A full Spring Boot starter for a library may contain the following components:

•  The auto configure module that contains the auto-configuration code.

•  The starter module that provides a dependency to the autoconfigure module as well as the library and any additional dependencies that are typically useful. In a nutshell, adding the starter should be enough to start using that library.Tip You  may  combine  the  auto-configuration  code  and  the  dependency  management  in  a  single module if you don’t need to separate those two concerns. Naming Please make sure to provide a proper namespace for your starter. Do not start your module names with spring-boot, even if you are using a different Maven groupId. We may offer an official support for the thing you’re auto-configuring in the future.Here is a rule of thumb. Let’s assume that you are creating a starter for "acme", name the auto-configure module acme-spring-boot-autoconfigure and  the  starter acme-spring-boot-starter.  If you only have one module combining the two, use acme-spring-boot-starter

Besides, if your starter provides configuration keys, use a proper namespace for them. In particular, do not include your keys in the namespaces that Spring Boot uses (e.g.server,management,spring,etc). These are "ours" and we may improve/modify them in the future in such a way it could break your things Make  sure  to trigger  meta-data  generation

so  that  IDE  assistance  is  available  for  your  keys  as well.  You  may  want  to  review  the  generated  meta-data  (META-INF/spring-configuration-metadata.json) to make sure your keys are properly documented.Autoconfigure module The autoconfigure module contains everything that is necessary to get started with the library. It may also contain configuration keys definition (@ConfigurationProperties) and any callback interface that can be used to further customize how the components are initialized.Tip You  should  mark  the  dependencies  to  the  library  as  optional  so  that  you  can  include  theautoconfigure  module  in  your  projects  more  easily.  If  you  do  it  that  way,  the  library  won’t  beprovided and Spring Boot will back off by default.Starter module The starter is an empty jar, really. Its only purpose is to provide the necessary dependencies to work with the library; see it as an opinionated view of what is required to get started.Do not make assumptions about the project in which your starter is added. If the library you are auto-configuring  typically  requires  other  starters,  mention  them  as  well.  Providing  a  proper  set  of default dependencies may be hard if the number of optional dependencies is high as you should avoid bringing unnecessary dependencies for a typical usage of the library。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容