创建maven项目
    引入编写starter所需要的spring依赖

    1. <dependency>
    2. <groupId>org.springframework.boot</groupId>
    3. <artifactId>spring-boot-configuration-processor</artifactId>
    4. <optional>true</optional>
    5. <version>2.2.1.RELEASE</version>
    6. </dependency>
    7. <dependency>
    8. <groupId>org.springframework.boot</groupId>
    9. <artifactId>spring-boot-autoconfigure</artifactId>
    10. <version>2.2.12.RELEASE</version>
    11. </dependency>
    1. 编写Properties类、主要用于接受spring-boot启动时候application.properties/yml文件的配置参数
    1. package com.enna.test;
    2. import org.springframework.boot.context.properties.ConfigurationProperties;
    3. import org.springframework.stereotype.Component;
    4. /**
    5. * @author DELL
    6. * @version 1.0
    7. * @date 2021/3/11 16:29
    8. */
    9. @Component
    10. @ConfigurationProperties(prefix = "test")
    11. public class PropertyDemo {
    12. private String name;
    13. private String age;
    14. public String getName() {
    15. return name;
    16. }
    17. public void setName(String name) {
    18. this.name = name;
    19. }
    20. public String getAge() {
    21. return age;
    22. }
    23. public void setAge(String age) {
    24. this.age = age;
    25. }
    26. }
    1. 编写AutoConfiguration配置文件
    1. package com.enna.test;
    2. import org.springframework.boot.context.properties.EnableConfigurationProperties;
    3. import org.springframework.context.annotation.Bean;
    4. import org.springframework.context.annotation.Configuration;
    5. /**
    6. * TODO
    7. *
    8. * @author DELL
    9. * @version 1.0
    10. * @date 2021/3/11 16:31
    11. */
    12. @Configuration
    13. @EnableConfigurationProperties(TestProperty.class)
    14. public class TestAutoConfiguration {
    15. //currentUsers为自定义测试新建的对象
    16. @Bean
    17. public CurrentUsers users(TestProperty testProperty) {
    18. TestUsers testUsers = new TestUsers();
    19. System.out.println( "注入testUsers" );
    20. System.out.println( testUsers );
    21. return testUsers;
    22. }
    23. }
    1. 在resource目录下面创建META-INF/spring.factories文件
      spring-boot创建starter项目 - 图1

    至此starter简易demo编写完成,采用maven的package打包 然后丢入所需要的starter项目
    spring-boot创建starter项目 - 图2