资讯专栏INFORMATION COLUMN

SpringBoot之Starter

kun_jian / 1723人阅读

摘要:序的主要用来简化依赖用的。本文主要分两部分,一部分是列出一些的依赖,另一部分是教你自己写一个。

SpringBoot的starter主要用来简化依赖用的。本文主要分两部分,一部分是列出一些starter的依赖,另一部分是教你自己写一个starter。

部分starters的依赖
Starter(Group ID: org.springframework.boot) 传递依赖于
spring-boot-starter-log4j2 ■ org.apache.logging.log4j:log4j-slf4j-impl
■ org.apache.logging.log4j:log4j-api
■ org.apache.logging.log4j:log4j-core
■ org.slf4j:jcl-over-slf4j
■ org.slf4j:jul-to-slf4j
spring-boot-starter-logging ■ ch.qos.logback:logback-classic
■ org.slf4j:jcl-over-slf4j
■ org.slf4j:jul-to-slf4j
■ org.slf4j:log4j-over-slf4j
spring-boot-starter-mail ■ org.springframework.boot:spring-boot-starter
■ org.springframework:spring-context
■ org.springframework:spring-context-support
■ com.sun.mail:javax.mail
spring-boot-starter-mobile ■ org.springframework.boot:spring-boot-starter
■ org.springframework.boot:spring-boot-starter-web
■ org.springframework.mobile:spring-mobile-device
spring-boot-starter-mustache ■ org.springframework.boot:spring-boot-starter
■ org.springframework.boot:spring-boot-starter-web
■ com.samskivert:jmustache
spring-boot-starter-redis ■ org.springframework.boot:spring-boot-starter
■ org.springframework.data:spring-data-redis
■ redis.clients:jedis
spring-boot-starter-remote-shell ■ org.springframework.boot:spring-boot-starter
■ org.springframework.boot:spring-boot-starter-actuator
■ org.crashub:crash.cli
■ org.crashub:crash.connectors.ssh (excludes org.codehaus.groovy:groovy-all)
■ org.crashub:crash.connectors.telnet (excludes javax.servlet:servlet-api, log4j :log4j, commons-logging:commons-logging)
■ org.crashub:crash.embed.spring(excludes org.springframework:spring-web, org.codehaus.groovy:groovy-all)
■ org.crashub:crash.plugins.cron (excludes org.codehaus.groovy:groovy-all)
■ org.crashub:crash.plugins.mail (excludes org.codehaus.groovy:groovy-all)
■ org.crashub:crash.shell (excludes org.codehaus.groovy:groovy-all)
■ org.codehaus.groovy:groovy
spring-boot-starter-security ■ org.springframework.boot:spring-boot-starter
■ org.springframework:spring-aop
■org.springframework.security:spring-security-config
■org.springframework.security:spring-security-web
spring-boot-starter-social-facebook ■org.springframework.boot:spring-boot-starter
■ org.springframework.boot:spring-boot-starter-web
■org.springframework.social:spring-social-config
■ org.springframework.social:spring-social-core
■ org.springframework.social:spring-social-web
■org.springframework.social:spring-social-facebook
spring-boot-starter-social-linkedin ■org.springframework.boot:spring-boot-starter
■ org.springframework.boot:spring-boot-starter-web
■org.springframework.social:spring-social-config
■ org.springframework.social:spring-social-core
■ org.springframework.social:spring-social-web
■org.springframework.social:spring-social-linkedin
spring-boot-starter-social-twitter ■org.springframework.boot:spring-boot-starter
■ org.springframework.boot:spring-boot-starter-web
■ org.springframework.social:spring-social-config
■ org.springframework.social:spring-social-core
■org.springframework.social:spring-social-web
■ org.springframework.social:spring-social-twitter
spring-boot-starter-test ■ junit:junit
■ org.mockito:mockito-core
■ org.hamcrest:hamcrest-core
■ org.hamcrest:hamcrest-library
■ org.springframework:spring-core(excludes commons-logging:commons-logging)
■ org.springframework:spring-test
spring-boot-starter-thymeleaf ■ org.springframework.boot:spring-boot-starter
■ org.springframework.boot:spring-boot-starter-web
■ org.thymeleaf:thymeleaf-spring4
■nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect
spring-boot-starter-tomcat ■ org.apache.tomcat.embed:tomcat-embed-core
■ org.apache.tomcat.embed:tomcat-embed-el
■org.apache.tomcat.embed:tomcat-embed-logging-juli
■org.apache.tomcat.embed:tomcat-embed-websocket
spring-boot-starter-undertow ■ io.undertow:undertow-core
■ io.undertow:undertow-servlet(excludes org.jboss.spec.javax.servlet:jboss-servlet-api_3.1_spec)
■ io.undertow:undertow-websockets-jsr
■ javax.servlet:javax.servlet-api
■ org.glassfish:javax.el
spring-boot-starter-validation ■ org.springframework.boot:spring-boot-starter
■ org.apache.tomcat.embed:tomcat-embed-el
■org.hibernate:hibernate-validator
spring-boot-starter-velocity ■ org.springframework.boot:spring-boot-starter
■ org.springframework.boot:spring-boot-starter-web
■ commons-beanutils:commons-beanutils
■ commons-collections:commons-collections
■ commons-digester:commons-digester
■ org.apache.velocity:velocity
■ org.apache.velocity:velocity-tools
■ org.springframework:spring-context-support
spring-boot-starter-web ■ org.springframework.boot:spring-boot-starter
■ org.springframework.boot:spring-boot-starter-tomcat
■ org.springframework.boot:spring-boot-starter-validation
■com.fasterxml.jackson.core:jackson-databind
■ org.springframework:spring-web
■ org.springframework:spring-webmvc
spring-boot-starter-websocket ■ org.springframework.boot:spring-boot-starter
■ org.springframework.boot:spring-boot-starter-web
■ org.springframework:spring-messaging
■org.springframework:spring-websocket
spring-boot-starter-ws ■ org.springframework.boot:spring-boot-starter
■ org.springframework.boot:spring-boot-starter-web ■org.springframework:spring-jms
■ org.springframework:spring-oxm
■ org.springframework.ws:spring-ws-core
■ org.springframework.ws:spring-ws-support
Reference

来自<>的附录B SpringBoot Starters的内容

如何自己写starter 主要步骤

1、选择已有的starters,在此基础上进行扩展.

2、创建自动配置文件并设定META-INF/spring.factories里的内容.

3、发布你的starter

添加依赖管理

        
            
                org.springframework.boot
                spring-boot-dependencies
                ${spring.boot.version}
                pom
                import
            
        
添加starter自己的依赖

        
            org.springframework.boot
            spring-boot-starter
        
        
            org.springframework.boot
            spring-boot-starter-web
        
新建configuration
@Configuration
@ComponentScan( basePackages = {"com.codecraft.actuator"} )
public class WebAutoConfiguration {

    /**
     * addViewController方法不支持placeholder的解析
     * 故在这里用变量解析出来
     */
    @Value("${actuator.web.base:}")
    String actuatorBase;

//    @Bean
//    public ActuatorNavController actuatorNavController(){
//        return new ActuatorNavController();
//    }

    @Bean
    public WebMvcConfigurerAdapter configStaticMapping() {
        return new WebMvcConfigurerAdapter() {
            @Override
            public void addViewControllers(ViewControllerRegistry registry) {
                //配置跳转
                registry.addViewController(actuatorBase+"/nav").setViewName(
                        "forward:/static/nav.html");
            }

            @Override
            public void addResourceHandlers(ResourceHandlerRegistry registry) {
                registry.addResourceHandler("/static/**").
                        addResourceLocations("classpath:/static/");
            }
        };
    }

}
修改/META-INF/spring.factories
# AutoConfigurations
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.codecraft.actuator.configuration.WebAutoConfiguration
发布
mvn clean install
引用
        
            com.codecraft
            spring-boot-starter-actuator-web
            1.0-SNAPSHOT
        
启动访问
mvn spring-boot:run

访问

http://localhost:8080/nav

note

Spring Boot:定制自己的starter

Boot your own infrastructure – Extending Spring Boot in five steps

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/65371.html

相关文章

  • SpringBoot非官方教程 | 第一篇:构建第一个SpringBoot工程

    摘要:简介它的设计目的就是为例简化开发,开启了各种自动装配,你不想写各种配置文件,引入相关的依赖就能迅速搭建起一个工程。它采用的是建立生产就绪的应用程序观点,优先于配置的惯例。另,本系列教程全部用的作为开发工具。 简介 spring boot 它的设计目的就是为例简化开发,开启了各种自动装配,你不想写各种配置文件,引入相关的依赖就能迅速搭建起一个web工程。它采用的是建立生产就绪的应用程序观...

    Cheriselalala 评论0 收藏0
  • 【Java入门】SpringBoot自动配置原理

    摘要:作者谭淼一运行原理的运行是由注解提供的。完成自动配置类。自动配置类主要作用是的配置核心,它会写在中,告知在启动时去读取该类并根据该类的规则进行配置。会检测是否存在类类会查看是否开启该自动配置。 作者:谭淼 一、运行原理 Spring Boot的运行是由注解@EnableAutoConfiguration提供的。 @Target({ElementType.TYPE}) @Retentio...

    468122151 评论0 收藏0
  • SpringBoot 2.X Kotlin 系列Hello World

    摘要:二教程环境三创建项目创建项目有两种方式一种是在官网上创建二是在上创建如图所示勾选然后点,然后一直默认最后点击完成即可。我们这里看到和普通的接口没有异同,除了返回类型是用包装之外。与之对应的还有,这个后面我们会讲到。 showImg(https://segmentfault.com/img/remote/1460000018819338?w=1024&h=500); 从去年开始就开始学习...

    warkiz 评论0 收藏0
  • 一起学习使用Spring Cloud NetflixEureka

    摘要:笔者也是初学者,本文从创建项目工程开始,一步一步开始讲解如何创建服务端和客户端,一起学习,共同进步。下面我们使用工具创建相关项目。配置其中两个属性表明这个应用是端,而不是端。至此,端和端已经部署成功。 前言 spring cloud为互联企业构建微服务提供了一整套的技术组件,其中Eureka是Spring Cloud体系中的核心。Netfix不是一个技术概念,它原本是国外一个视频网站的...

    李义 评论0 收藏0
  • 从0开始学springboot启蒙篇

    摘要:下载地址百度谷歌一大堆以下介绍如何使用自带的下载下载请选择版本创建一个项目输入输入输入修改为如下将自动下载以及相关依赖包至此工程已经搭建完毕,下一篇将是一个 (why)为什么springboot火遍全世界 springboot 有个好爹spring springboot 遗传了爹的优秀基因而生 大神们都在讲服务化(service),springboot做服务化再合适不过了 sprin...

    zhangxiangliang 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<