springboot项目使用自定义starter

news/2024/9/22 13:41:09/文章来源:https://www.cnblogs.com/q202105271618/p/18333526

首先是自定义的starter部分

pom文件

<?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"><modelVersion>4.0.0</modelVersion><groupId>com.common</groupId><artifactId>common-service</artifactId><version>1.0-SNAPSHOT</version><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.18</version></parent><properties><java.version>1.8</java.version><skipTests>true</skipTests></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin></plugins></build></project>

  代码部分

package com.common.starter;/*** @Description:* @Author: tutu-qiuxie* @Create: 2024/7/30 22:36*/
public interface TestService {void testPlay();
}package com.common.starter;/*** @Description:* @Author: tutu-qiuxie* @Create: 2024/7/30 22:37*/
public class TestServiceImpl implements TestService{@Overridepublic void testPlay() {System.out.println("自定义starter测试打印");}
}

  

package com.common.starter.config;import com.common.starter.TestService;
import com.common.starter.TestServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** @Description:* @Author: tutu-qiuxie* @Create: 2024/7/30 22:35*/
@Configuration
@ConditionalOnClass(TestService.class)
public class MyAutoConfiguration {@Beanpublic TestService testService(){return new TestServiceImpl();}}

  配置类部分

 

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.common.starter.config.MyAutoConfiguration

  使用idea打包到本地maven仓库

 使用部分

 使用方完整pom

<?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"><modelVersion>4.0.0</modelVersion><groupId>com.example</groupId><artifactId>consumer-service</artifactId><version>1.0-SNAPSHOT</version><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.18</version></parent><dependencies><dependency><groupId>com.common</groupId><artifactId>common-service</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!--引入junit单元测试依赖--><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency></dependencies></project>

  启动类

package com.example;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;/*** @Description:* @Author: tutu-qiuxie* @Create: 2024/7/30 22:54*/
@SpringBootApplication
public class TestApplication {public static void main(String[] args) {SpringApplication.run(TestApplication.class,args);}
}

  测试类部分

package com.example;import com.common.starter.TestService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;/*** @Description:* @Author: tutu-qiuxie* @Create: 2024/7/30 22:52*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class Tests {@Autowiredprivate TestService testService;@Testpublic void test002(){testService.testPlay();}}

  

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/774311.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

SQL执行顺序和逻辑

SQL执行顺序和逻辑 MySQL的执行顺序:(9) SELECT (6) SUM(聚合函数) (10) DISTINCT <select_list> (1) FROM <left_table> (3) <join_type> JOIN <right_table> (2) ON <join_condition> (4) WHERE <where_condition> …

后缀数组 - half

后缀数组 后缀数组可以解决有关后缀的问题废话。那么暴力做法肯定是把每个后缀全部取出来,然后按照字典序排序,但是这样复杂度是 \(\Theta(n^2\log n)\) 的。 后缀数组可以解决以下问题:最长重复子串 多个串的最长公共子串 不同子串个数算法详解 面对这些问题,我们需要 \(3…

Misc专项

一:文件操作与隐写 1、文件类型的识别 1、文件头完好情况: (1)file命令 使用file命令识别:识别出file.doc为jpg类型(2)winhex 通过winhex工具查看文件头类型,根据文件头部内容去判断文件的类型eg:JPG类型(3)notepad++ 下载HEXeditor插件,查看文件的头部信息,和010e…

zookeeper未授权访问(CVE-2014-085)

漏洞描述 默认安装配置完的zookeeper允许未授权访问,管理员未配置访问控制列表(ACL)。导致攻击者可以在默认开放的2181端口下通过执行envi命令获得大量敏感信息(系统名称、java环境)导致任意用户可以在网络不受限的情况下进行未授权访问读取数据 漏洞影响 Apache ZooKeepe…

如何自动实现本地AD中禁用的用户从地址列表中隐藏掉?

我的博客园:https://www.cnblogs.com/CQman/ 如何自动实现本地AD中禁用的用户从地址列表中隐藏掉?需求信息:用户本地AD用户通过ADConnect同步到O365,用户想实现在本地已做同步的OU中禁用某一用户后,其可以自动实现把该用户从地址列表中隐藏掉。用户的ADConnect同步工具装在…

go高并发之路——消息中间件kafka(上)

一般高并发的业务都是某个时间段的请求量特别大,比如本人负责的直播业务,基本上一天就两个高峰段:早上和晚上的特定时间段。其它的时间里,流量基本都比较平稳。那么面对流量高峰,我们可以采取哪些措施呢?常见的有服务器和DB提前扩容、监控告警(盯监控)、流量削峰、加缓…

数组及数组JVM内存划分day4

java中第一个存储数据的容器:数组特点:1、数组的长度大小是固定的2、同一个数组中,存储的元素数据类型是一样的数组的定义语句格式:数据类型[] 数组名;举例:int[] arr; // 定义了一个可以存储int类型的一维数组,数组名叫做arr数组没有初始化,无法直接使用,数组是我们第…

借助流程表单设计器开源为流程化办公赋能

借助流程表单设计器做好数据管理工作,为行业发展贡献整套低代码技术平台解决方案。在经济高速发展的今天,想要实现流程化办公和数字化转型,需要利用更优质的平台为其加油助力。低代码技术平台、流程表单设计器开源为各行各业流程化办公高效赋能,一起摆脱信息孤岛、部门沟通…

AI/机器学习(计算机视觉/NLP)方向面试复习1

1. 判断满二叉树 所有节点的度要么为0,要么为2,且所有的叶子节点都在最后一层。 #include <iostream> using namespace std; class TreeNode { public:int val;TreeNode* left;TreeNode* right; //创建的时候输入参数x,会把x给val,nullptr给left和right TreeNode(int…

【PlantSaver】电容式土壤湿度传感器使用及原理(并以Arduino实验)

1.湿度检测原理 关于这个传感器检测的原理,网上找的资料不多。类似传感器经典的设计是美国DECAGON 公司生产的ECH2O 系列传感器。其结构如下:式中: ε0 = 8.85410-12 为真空介电常数,单位 F/m; S 为板间遮盖面积,单位 m2 ; C 为板间电容量,单位F; δ 为板件厚度,m; ε …

九章算术与线性方程组

通过介绍《九章算术》中线性方程组理论的发展,使学生 认识到,中国古代的数学研究不仅开展的较早,在一段时间内处于世界领先地 位,此增强学生的文化自信与民族自豪感,鼓励学生探寻我国传统文化中的瑰宝 遗珠.

工单管理系统全攻略:找到你的完美匹配

国内外主流的10款项目工单管理系统对比:PingCode、Worktile、浪潮云工单管理系统、华为企业智能工单系统、金蝶云苍穹、紫光软件管理系统、Jira、Asana、ServiceNow、Smartsheet。在管理日益复杂的个人项目时,找到一款能够真正符合需求的管理软件,常常是许多人面临的难题。市…