Skip to content
Blog
Backend10 min read

Custom Spring Boot Starters: Packaging Shared Infrastructure

B

BADJO Dibéa Koffi

Published on May 3, 2026

The Copy-Paste Problem

You have 8 microservices. Each needs JWT auth, structured logging, health checks, metrics, and error handling. Every new service starts by copying configs from an existing one. Within 6 months, each has a slightly different version.

What Is a Starter?

A Maven dependency that auto-configures beans when on the classpath. Add it to pom.xml, get all shared infrastructure — zero copy-paste.

Auto-Configuration

@AutoConfiguration
@ConditionalOnWebApplication(type = Type.SERVLET)
@EnableConfigurationProperties(JwtProperties.class)
public class JwtAutoConfiguration {
 
    @Bean
    @ConditionalOnMissingBean
    public JwtUtil jwtUtil(JwtProperties props) {
        return new JwtUtil(props.getSecret(), props.getExpiration());
    }
 
    @Bean
    @ConditionalOnProperty(name = "company.security.enabled", matchIfMissing = true)
    public SecurityFilterChain securityFilterChain(HttpSecurity http, JwtFilter jwtFilter) throws Exception {
        return http
            .csrf(AbstractHttpConfigurer::disable)
            .sessionManagement(s -> s.sessionCreationPolicy(STATELESS))
            .addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class)
            .build();
    }
}

Key annotations:

  • @ConditionalOnMissingBean — doesn't override if the service defines its own
  • @ConditionalOnProperty — can be disabled via config

Using the Starter

<dependency>
    <groupId>com.company</groupId>
    <artifactId>my-company-spring-boot-starter</artifactId>
    <version>1.2.0</version>
</dependency>

That's it. JWT auth, logging, error handling, health checks — all configured.

The Result

Before: spinning up a new service took 2-3 days. Now: 20 minutes. When we fix a security issue, every service gets the fix on their next dependency update.

spring-bootauto-configurationjavamicroservices
Share

Comments