前言
springboot支持自定义starter,可以用来封装一些自定义的组件,比如fastdfs,ftp等等工具类,封装成starter之后,直接引入就可以了。
步骤
新建一个maven项目,在pom文件里面引入相关依赖jar包。
主要需要引入spring-boot-configuration-processor
和spring-boot-autoconfigure
,这个引用是自动生成配置提示相关信息的,编译之后就会自动生成spring-configuration-metadata.json文件,这样就可以提示了。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
&