Performance: Bean concept in Spring
MEDIUM IMPACT
This concept affects application startup time and memory usage by managing object creation and lifecycle.
@Component public class Service { private final Repository repo; public Service(Repository repo) { this.repo = repo; } } @Component public class Repository {}
public class Service {
private final Repository repo = new Repository();
// manual new object creation without Spring
}| Pattern | Bean Creation | Memory Usage | Startup Time | Verdict |
|---|---|---|---|---|
| Manual object creation | Multiple unmanaged instances | High due to duplicates | Longer due to no container optimization | [X] Bad |
| Spring-managed singleton beans | Single shared instance | Optimized minimal usage | Faster due to container control | [OK] Good |
| Eager loading many beans | All beans created at startup | Moderate to high | Slower startup | [!] OK |
| Lazy initialization beans | Created on demand | Lower initial memory | Faster startup | [OK] Good |