开发通用的模块或库,向往在其他模块中使用;或者大项目拆分成多个模块,每个模块需要独立维护和复用,为方便独立开发、测试和复用,需要将该模块自定义为springboot的starter。
要实现自定义starter,最核心的是实现组件的自动配置。
1、创建starter项目
创建一个普通的Maven项目,建议命名方式***-spring-boot-starter,pom文件引入依赖:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.14</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>
2、实现业务功能
创建普通java类HelloService
public class HelloService {
private String msg;
pub

最低0.47元/天 解锁文章
3105

被折叠的 条评论
为什么被折叠?



