Performance: Custom auto-configuration
MEDIUM IMPACT
Custom auto-configuration affects application startup time and memory usage by adding or skipping bean creation during Spring Boot app initialization.
package com.example.autoconfig; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration @ConditionalOnClass(HeavyService.class) @ConditionalOnProperty(prefix = "myapp.heavy", name = "enabled", havingValue = "true", matchIfMissing = false) public class MyAutoConfig { @Bean public HeavyService heavyService() { return new HeavyService(); } }
package com.example.autoconfig; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class MyAutoConfig { @Bean public HeavyService heavyService() { return new HeavyService(); } }
| Pattern | Bean Creation | Startup Delay | Memory Usage | Verdict |
|---|---|---|---|---|
| Unconditional bean creation | Always creates bean | Adds 100-200ms delay | Higher memory use | [X] Bad |
| Conditional bean creation | Creates bean only if needed | No extra delay if skipped | Lower memory use | [OK] Good |