Custom starter

Posted Jun 5, 20202 min read

Custom starter naming rules

The starter provided by SpringBoot is named after `spring-boot-starter-xxx`. Officially recommend that custom starters use the naming rules of `xxx-spring-boot-starter`. To distinguish the starter provided by the SpringBoot ecosystem

The whole process is divided into two parts:

- Custom starter

- Use starter

First, complete the custom starter

(1) New maven jar project, the project name is zdy-spring-boot-starter, import dependencies:





(2) Write javaBean



@ConfigurationProperties(prefix = "simplebean")

public class SimpleBean {

private int id;

private String name;

public int getId() {

return id;


public void setId(int id) { = id;


public String getName() {

return name;


public void setName(String name) { = name;



public String toString() {

return "SimpleBean{" +

"id=" + id +

", name='" + name +'\'' +




(3) Write configuration class MyAutoConfiguration



@ConditionalOnClass //@ConditionalOnClass:Automatic configuration when there is a specified class in the classpath classpath

public class MyAutoConfiguration {

static {

System.out.println("MyAutoConfiguration init....");



public SimpleBean simpleBean(){

return new SimpleBean();



(4) Create /META-INF/spring.factories under resources

Note:META-INF is a manually created directory, spring.factories is also a manually created file, configure your own automatic configuration class in this file





I just learned the "Java Engineer High Salary Training Camp" of Lagou Education, and I answered when I saw what I just learned. I hope Lagou can push me to the company I want to go to. Goal:byte! !