当前位置: 首页 > news >正文

springBoot中starter

springBoot项目中引入starter

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

<dependency><groupId>com.ydl</groupId><artifactId>xxl-job-spring-boot-starter</artifactId><version>0.0.1-SNAPSHOT</version>
</dependency>

xxl-job-spring-boot-starter

目录结构:

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

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>xxl-job-starter</artifactId><groupId>com.xiaozhen</groupId><version>0.0.1-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>xxl-job-spring-boot-starter</artifactId><dependencies><dependency><groupId>com.ydl</groupId><artifactId>xxl-job-spring-boot-autoconfiguration</artifactId><version>0.0.1-SNAPSHOT</version></dependency></dependencies></project>

pom.properties

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

xxl-job-spring-boot-autoconfiguration

目录文件

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

/*** 注解解释:** @Configuration  //指定这个类是一个配置类* @ConditionalOnXXX  //在指定条件成立的情况下自动配置类生效* @AutoConfigureAfter  //指定自动配置类的顺序* @Bean  //给容器中添加组件* @ConfigurationPropertie结合相关xxxProperties类来绑定相关的配置* @EnableConfigurationProperties //让xxxProperties生效加入到容器中*/
@Component
@EnableConfigurationProperties({XxlJobProperties.class})
public class XxlJobAutoConfiguration {private static Logger logger = LoggerFactory.getLogger(XxlJobAutoConfiguration.class);@Resourceprivate XxlJobProperties xxlJobProperties;public XxlJobAutoConfiguration() {}/*** 配置信息**/@Beanpublic XxlJobSpringExecutor xxlJobExecutor() {logger.info(">>>>>>>>>>> xxl-job config init.");XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();xxlJobSpringExecutor.setAdminAddresses(this.xxlJobProperties.getAdminAddresses());xxlJobSpringExecutor.setAppName(this.xxlJobProperties.getExecutorAppName());xxlJobSpringExecutor.setIp(this.xxlJobProperties.getExecutorIp());xxlJobSpringExecutor.setPort(this.xxlJobProperties.getExecutorPort());xxlJobSpringExecutor.setAccessToken(this.xxlJobProperties.getAccessToken());xxlJobSpringExecutor.setLogPath(this.xxlJobProperties.getExecutorLogPath() + this.xxlJobProperties.getExecutorAppName());xxlJobSpringExecutor.setLogRetentionDays(this.xxlJobProperties.getExecutorLogRetentionDays());return xxlJobSpringExecutor;}
}

xxlJobProperties

@ConfigurationProperties(prefix = "xxl.job"
)
public class XxlJobProperties {private String adminAddresses = "http://localhost:8093/xxl-job-admin";private String accessToken;private String executorAppName = "xxl-job-executor-default";private String executorIp;private int executorPort = 9999;private String executorLogPath = "/data/applogs/xxl-job/jobhandler/";private int executorLogRetentionDays = 30;public XxlJobProperties() {}
}

pom.xml导入相关的jar包

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><artifactId>xxl-job-starter</artifactId><groupId>com.xiaozhen</groupId><version>0.0.1-SNAPSHOT</version></parent><groupId>com.ydl</groupId><artifactId>xxl-job-spring-boot-autoconfiguration</artifactId><version>0.0.1-SNAPSHOT</version><name>xxl-job-spring-boot-autoconfiguration</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version></properties><dependencies><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.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency><!-- xxl-job-core --><dependency><groupId>com.xuxueli</groupId><artifactId>xxl-job-core</artifactId><version>2.1.1</version></dependency></dependencies>
</project>

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

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

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

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.alibaba.boot.dubbo.autoconfigure.DubboAutoConfigurationorg.springframework.context.ApplicationListener=\
com.alibaba.boot.dubbo.context.event.OverrideDubboConfigApplicationListener,\
com.alibaba.boot.dubbo.context.event.WelcomeLogoApplicationListener,\
com.alibaba.boot.dubbo.context.event.AwaitingNonWebApplicationListener

public class AwaitingNonWebApplicationListener implements ApplicationListener<ApplicationReadyEvent> {@Order //最低优先级确保最后执行
public class OverrideDubboConfigApplicationListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {@Order(LoggingApplicationListener.DEFAULT_ORDER + 1)
public class WelcomeLogoApplicationListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {

http://www.lryc.cn/news/238923.html

相关文章:

  • Linux学习笔记-Ubuntu下使用Crontab设置定时任务
  • 动态规划求数组中相邻两数的最小差值( 即相差的绝对值 ) java 实现
  • webGL开发微信小游戏
  • leetcode面试经典150题——29 三数之和
  • 数据分析基础之《jupyter notebook工具》
  • Android Studio Error “Unsupported class file major version 61“---异常信息记录
  • javaScript 内存管理
  • Idea2023 Springboot web项目正常启动,页面展示404解决办法
  • Android手机如何用Charles抓包HTTPS接口
  • Oracle for Windows安装和配置——Oracle for Windows net配置
  • C#中.NET 7.0 Windows窗体应用通过EF访问已有数据库并实现追加、删除、修改、插入记录
  • 【文末送书】计算机网络 | IO多路转接技术 | poll/epoll详解
  • 【Linux】 uptime命令使用
  • 数学建模-图与网络模型解题方法和代码实现
  • 宏集新闻 | 虹科传感器事业部正式更名为宏集科技
  • DataFunSummit:2023年数据基础架构峰会-核心PPT资料下载
  • 解析大型语言模型的训练、微调和推理的运行时性能
  • MAX/MSP SDK学习06:内存管理
  • python网络通信之基础知识填坑
  • 【腾讯云云上实验室-向量数据库】腾讯云开创新时代,发布全新向量数据库Tencent Cloud VectorDB
  • 【图像分类】【深度学习】【Pytorch版本】GoogLeNet(InceptionV4)模型算法详解
  • opencv dots_image_kernel
  • 使用pytorch利用神经网络原理进行图片的训练(持续学习中....)
  • 2023年中国合成云母行业现状及市场格局分析[图]
  • Vue3+Vite实现工程化,插值表达式和v-text以及v-html
  • 艾泊宇产品战略:灵感于鬼屋,掌握打造卓越用户体验的关键要素
  • 深度学习环境配置(Anaconda+pytorch+pycharm+cuda)
  • 不是说人工智能是风口吗,那为什么工作还那么难找?
  • new Vue() 发生了什么
  • 【算法】二叉树的存储与遍历模板