• springBoot中starter


    springBoot项目中引入starter

    项目引入xxljob,仅需要导入对应的starter包,即可进行快速开发

    1. <dependency>
    2. <groupId>com.ydlgroupId>
    3. <artifactId>xxl-job-spring-boot-starterartifactId>
    4. <version>0.0.1-SNAPSHOTversion>
    5. dependency>

    xxl-job-spring-boot-starter

    目录结构:

    pom.xml中仅导入对应的xxl-job-spring-boot-autoconfiguration依赖

    1. "1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    5. <parent>
    6. <artifactId>xxl-job-starterartifactId>
    7. <groupId>com.xiaozhengroupId>
    8. <version>0.0.1-SNAPSHOTversion>
    9. parent>
    10. <modelVersion>4.0.0modelVersion>
    11. <artifactId>xxl-job-spring-boot-starterartifactId>
    12. <dependencies>
    13. <dependency>
    14. <groupId>com.ydlgroupId>
    15. <artifactId>xxl-job-spring-boot-autoconfigurationartifactId>
    16. <version>0.0.1-SNAPSHOTversion>
    17. dependency>
    18. dependencies>
    19. project>

    pom.properties

    1. version=0.0.1-SNAPSHOT
    2. groupId=com.xiaozhen
    3. artifactId=xxl-job-spring-boot-starter

    xxl-job-spring-boot-autoconfiguration

    目录文件

     xxlJobAutoConfiguration为配置类,springBoot启动时会加重

    1. /**
    2. * 注解解释:
    3. *
    4. * @Configuration //指定这个类是一个配置类
    5. * @ConditionalOnXXX //在指定条件成立的情况下自动配置类生效
    6. * @AutoConfigureAfter //指定自动配置类的顺序
    7. * @Bean //给容器中添加组件
    8. * @ConfigurationPropertie结合相关xxxProperties类来绑定相关的配置
    9. * @EnableConfigurationProperties //让xxxProperties生效加入到容器中
    10. */
    11. @Component
    12. @EnableConfigurationProperties({XxlJobProperties.class})
    13. public class XxlJobAutoConfiguration {
    14. private static Logger logger = LoggerFactory.getLogger(XxlJobAutoConfiguration.class);
    15. @Resource
    16. private XxlJobProperties xxlJobProperties;
    17. public XxlJobAutoConfiguration() {
    18. }
    19. /**
    20. * 配置信息
    21. **/
    22. @Bean
    23. public XxlJobSpringExecutor xxlJobExecutor() {
    24. logger.info(">>>>>>>>>>> xxl-job config init.");
    25. XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
    26. xxlJobSpringExecutor.setAdminAddresses(this.xxlJobProperties.getAdminAddresses());
    27. xxlJobSpringExecutor.setAppName(this.xxlJobProperties.getExecutorAppName());
    28. xxlJobSpringExecutor.setIp(this.xxlJobProperties.getExecutorIp());
    29. xxlJobSpringExecutor.setPort(this.xxlJobProperties.getExecutorPort());
    30. xxlJobSpringExecutor.setAccessToken(this.xxlJobProperties.getAccessToken());
    31. xxlJobSpringExecutor.setLogPath(this.xxlJobProperties.getExecutorLogPath() + this.xxlJobProperties.getExecutorAppName());
    32. xxlJobSpringExecutor.setLogRetentionDays(this.xxlJobProperties.getExecutorLogRetentionDays());
    33. return xxlJobSpringExecutor;
    34. }
    35. }

    xxlJobProperties

    1. @ConfigurationProperties(
    2. prefix = "xxl.job"
    3. )
    4. public class XxlJobProperties {
    5. private String adminAddresses = "http://localhost:8093/xxl-job-admin";
    6. private String accessToken;
    7. private String executorAppName = "xxl-job-executor-default";
    8. private String executorIp;
    9. private int executorPort = 9999;
    10. private String executorLogPath = "/data/applogs/xxl-job/jobhandler/";
    11. private int executorLogRetentionDays = 30;
    12. public XxlJobProperties() {
    13. }
    14. }

    pom.xml导入相关的jar包

    1. "1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    4. <modelVersion>4.0.0modelVersion>
    5. <parent>
    6. <artifactId>xxl-job-starterartifactId>
    7. <groupId>com.xiaozhengroupId>
    8. <version>0.0.1-SNAPSHOTversion>
    9. parent>
    10. <groupId>com.ydlgroupId>
    11. <artifactId>xxl-job-spring-boot-autoconfigurationartifactId>
    12. <version>0.0.1-SNAPSHOTversion>
    13. <name>xxl-job-spring-boot-autoconfigurationname>
    14. <description>Demo project for Spring Bootdescription>
    15. <properties>
    16. <java.version>1.8java.version>
    17. properties>
    18. <dependencies>
    19. <dependency>
    20. <groupId>org.springframework.bootgroupId>
    21. <artifactId>spring-boot-starterartifactId>
    22. dependency>
    23. <dependency>
    24. <groupId>org.springframework.bootgroupId>
    25. <artifactId>spring-boot-configuration-processorartifactId>
    26. <optional>trueoptional>
    27. dependency>
    28. <dependency>
    29. <groupId>org.projectlombokgroupId>
    30. <artifactId>lombokartifactId>
    31. <optional>trueoptional>
    32. dependency>
    33. <dependency>
    34. <groupId>org.springframework.bootgroupId>
    35. <artifactId>spring-boot-starter-testartifactId>
    36. <scope>testscope>
    37. <exclusions>
    38. <exclusion>
    39. <groupId>org.junit.vintagegroupId>
    40. <artifactId>junit-vintage-engineartifactId>
    41. exclusion>
    42. exclusions>
    43. dependency>
    44. <dependency>
    45. <groupId>com.xuxueligroupId>
    46. <artifactId>xxl-job-coreartifactId>
    47. <version>2.1.1version>
    48. dependency>
    49. dependencies>
    50. project>

    spring.factories文件(spring启动的时候会加载此文件中的配置类)

    1. org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
    2. com.ydl.xxljobspringbootautoconfiguration.XxlJobAutoConfiguration

    另外这个spring.factories文件还可配置监听类

    1. org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
    2. com.alibaba.boot.dubbo.autoconfigure.DubboAutoConfiguration
    3. org.springframework.context.ApplicationListener=\
    4. com.alibaba.boot.dubbo.context.event.OverrideDubboConfigApplicationListener,\
    5. com.alibaba.boot.dubbo.context.event.WelcomeLogoApplicationListener,\
    6. com.alibaba.boot.dubbo.context.event.AwaitingNonWebApplicationListener

     

    1. public class AwaitingNonWebApplicationListener implements ApplicationListener {
    2. @Order //最低优先级确保最后执行
    3. public class OverrideDubboConfigApplicationListener implements ApplicationListener {
    4. @Order(LoggingApplicationListener.DEFAULT_ORDER + 1)
    5. public class WelcomeLogoApplicationListener implements ApplicationListener {

     

  • 相关阅读:
    c语言进阶篇:指针(五)
    CSDN写作表情emoji大全
    大数据-74 Kafka 高级特性 稳定性 - 控制器、可靠性 副本复制、失效副本、副本滞后 多图一篇详解
    网络渗透课2
    整合easy-es后。调接口能返回,但是一直会报错
    esp32开发板学习
    动物数据集+动物分类识别训练代码(Pytorch)
    元宇宙系列之AI虚拟人:“人”潮汹涌 探路未来
    搭建算法接口及访问——Nginx、fastapi、postman配置使用
    Unity之ShaderGraph如何实现旋涡效果
  • 原文地址:https://blog.csdn.net/qq_36042938/article/details/134476747