springboot自定义stater启动流程
作者:好歹取个名字 发布时间:2023-06-07 06:33:45
标签:springboot,自定义,stater,启动
springboot启动时自动加载application.properties或者application.yml,如何定义自己的配置让springboot自动识别:
首先我们新建一个maven工程打包方式选择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>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.ruobbo.xxl</groupId>
<artifactId>ruobbo.xxl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.0.1</version>
</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>
</dependencies>
<!-- 项目部署配置 (上传到 * 的配置) -->
<distributionManagement>
<repository>
<id>releases</id>
<url>http://192.168.1.99:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://192.168.1.99:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>
然后是配置读取
@ConfigurationProperties(prefix = "xxl.job.executor")
@Data
public class XxlProperties {
private String adminAddresses;
private String appName;
private String ip;
private int port;
private String accessToken;
private String logPath;
private int logRetentionDays;
private String basePackages;
}
将读取到的配置注入到bean中,然后加载到spring bean容器中
@Configuration
@EnableConfigurationProperties(XxlProperties.class)
public class XxlAutoConfiguration {
private Logger logger = LoggerFactory.getLogger(XxlAutoConfiguration.class);
@Resource
private XxlProperties xxlProperties;
@Bean(initMethod = "start", destroyMethod = "destroy")
public XxlJobSpringExecutor xxlJobExecutor() {
logger.info(">>>>>>>>>>> xxl-job config init.");
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(xxlProperties.getAdminAddresses());
xxlJobSpringExecutor.setAppName(xxlProperties.getAppName());
xxlJobSpringExecutor.setIp(xxlProperties.getIp());
xxlJobSpringExecutor.setPort(xxlProperties.getPort());
xxlJobSpringExecutor.setAccessToken(xxlProperties.getAccessToken());
xxlJobSpringExecutor.setLogPath(xxlProperties.getLogPath());
xxlJobSpringExecutor.setLogRetentionDays(xxlProperties.getLogRetentionDays());
return xxlJobSpringExecutor;
}
}
最后在resources目录下添加META-INF文件夹添加spring.factories文件,文件内容为指定要初始化springbean的类全路径
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\com.ruobbo.xxl.XxlAutoConfiguration
使用过程中引入包
<dependency>
<groupId>com.ruobbo.xxl</groupId>
<artifactId>ruobbo.xxl</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
然后添加配置到application.properties或者application.yml
总结
以上所述是小编给大家介绍的springboot自定义stater启动流程网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
来源:https://blog.csdn.net/qq_30920479/article/details/102636699
0
投稿
猜你喜欢
- 一、背景spring-data-mongo 实现了基于 MongoDB 的 ORM-Mapping 能力,通过一些简单的注解、Query封装
- 前言Java线程池中提交任务运行,通常使用execute()方法就足够了。那如果想要实现在主线程中阻塞获取线程池任务运行的结果,该怎么办呢?
- 早期的项目比较简单,多是用JSP 、Servlet + JDBC 直接搞定,后来使用 Struts1(Struts2)+Spring+Hib
- 一、题目给出二叉搜索树的根节点,该树的节点值各不相同,请你将其转换为累加树(Greater Sum Tree),使每个节点 node 的新值
- JDK12的五大重要新特性Java12在March 19, 2019发布了。在2017年发布Java 9之后,Java平台发布节奏已从每3年
- SpringBoot 整合 Redis 数据库实现数据缓存的本质是整合 Redis 数据库,通过对需要“缓存&r
- 一、使用mybatis-spring-boot-starter1、添加依赖<dependency> <grou
- java中初始化MediaRecorder实现代码:private boolean initializeVideo() { &
- 引言: 在Spring Boot应用中,基于数据某个字段进行排序是一个非常常用的需求,这里将给出Sort的三种常用用法,基于分页的应用,大家
- java实现读取、删除文件夹下的文件package test.com;import java.io.File;import java.io.
- 前言自从国产之光fastjson频频暴雷,jackson json的使用是越来越广泛了。尤其是spring家族把它搞成了默认的JSON处理包
- 前言:各位小伙伴们,大家好,一日不见,如隔一日,今天我给大家分享一下大家在学习java过程当中遇到的一个问题,也是一道面试题,java中,O
- 一、@RestController 注解在 Spring Boot 中的 Controller 中使用 @RestController 注解
- Java CharArrayReader流一、CharArrayReader流定义API说明:该类实现了一个可用作字符输入流的字符缓冲区,即
- 前言:小编引入的图片和文字描述都是来自于尚硅谷的视频讲解,在此感谢尚硅谷的老师,同时也结合 seata文档官方文档进行整合项目地址(gite
- 自从SEOTcs系统11月份24日更新了一下SEO得分算法以来,一直困扰我的一个问题出现了,java的数据job任务,在执行过程中会经常报以
- 错误展示:Information:java: Errors occurred while compiling module 'emp
- Json的简介JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。它基于ECMAScript的一个
- SpringBoot项目经常将连接数据库的密码明文放在配置文件里,安全性就比较低一些,尤其在一些企业对安全性要求很高,因此我们就考虑如何对密
- 一、事务的基本原理Spring事务的本质其实就是数据库对事务的支持,没有数据库的事务支持,spring是无法提供事务功能的。对于纯JDBC操