Build Spring Boot Starter Project

https://www.notion.so/Build-Spring-Boot-Starter-Project-9ce098c683144dc6bd7f34ad338f8bea

Two Java Files

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
@ConfigurationProperties(prefix = "spring.ftsi")
public class IndexServiceAutoConfigurationProperties {

}

@Configuration
@EnableConfigurationProperties(IndexServiceAutoConfigurationProperties.class)
@ConditionalOnClass(IndexService.class)
@ConditionalOnProperty(prefix = "spring.ftsi", name = "enabled", matchIfMissing = true)
public class IndexServiceAutoConfiguration {

    @Autowired
    private IndexServiceAutoConfigurationProperties properties;

    @Bean
    @ConditionalOnMissingBean(IndexService.class)
    public IndexService indexService() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        IndexService service = new IndexService();
        return service;
    }
}

File: /src/main/resources/META-INF/spring.factories

1
2
3
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
net.bndy.ftsi.starter.IndexServiceAutoConfiguration

Usage

application.yml

1
2
3
4
spring:
  ftsi:
    property1: ...
    property2: ...

java

1
2
3
4
5
6
7
8
9
10
@SpringBootApplication
public class Application {

    @Autowried
    IndexService indexService;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
This post is licensed under CC BY 4.0 by the author.