快速编写springBoot-starter插件

 

第一步 引入starter相关的maven依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-autoconfigure</artifactId>
</dependency>

第二步 创建starter所需要的自动装配的类例如

@Configuration//必须加
@EnableAutoConfiguration//启动自动装配必须加
@EnableConfigurationProperties({JobProperty.class})//引入相关的配置类可选
@Slf4j
public class JobAutoConfiguration {

//以下是改starter项目的需要的注入的bean
    @Bean
    @ConditionalOnMissingBean
    public JobProperty jobProperty() {
        return new JobProperty();
    }

    @Bean(initMethod = "start", destroyMethod = "destroy")
    public XxlJobSpringExecutor xxlJobExecutor() {
        log.info(">>>>>>>>>>> xxl-job config init.");
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(jobProperty().getAdminAddresses());
        xxlJobSpringExecutor.setAppName(jobProperty().getAppName());
        xxlJobSpringExecutor.setIp(jobProperty().getIp());
        xxlJobSpringExecutor.setPort(jobProperty().getPort());
        xxlJobSpringExecutor.setAccessToken(jobProperty().getAccessToken());
        xxlJobSpringExecutor.setLogPath(jobProperty().getLogPath());
        xxlJobSpringExecutor.setLogRetentionDays(jobProperty().getLogRetentionDays());

        return xxlJobSpringExecutor;
    }
}

第三步 resource 下创建MATE-INF文件夹创建spring.factories文件

添加内容为

org.springframework.boot.autoconfigure.EnableAutoConfiguration=//先前编写好的自动装配的类,包名路径如 cn.xx.xxx.JobAutoConfiguration 

第四步 打包,然后在索要使用的项目里加入改项目的maven依赖,便使用。

https://www.bilibili.com/video/BV1Va4y1a72H/

素质三连,新人求关注

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值