• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aspectran / aspectran / #4738

01 Nov 2025 10:48PM UTC coverage: 38.181% (+0.2%) from 37.972%
#4738

push

github

topframe
Refactor: Overhaul FactoryBean and factory-method lifecycle

This commit introduces a comprehensive overhaul of the bean creation lifecycle, specifically for beans produced by a FactoryBean or a factory-method. The primary goal is to fix a critical bug where the factory instance was incorrectly injected as a dependency instead of its
product.

Key changes include:

- **Correct Dependency Injection:** The core logic in `AbstractBeanRegistry` and `AbstractBeanFactory` has been refactored to ensure that when a `FactoryBean` is requested as a dependency (e.g., in a constructor argument or autowired field), the container now correctly provides the
object created by the factory (`getObject()`) rather than the factory itself.

- **Thread-Safe Singleton Creation:** The `getScopedBean` method in `AbstractBeanRegistry` now employs a robust double-checked locking mechanism. This ensures that singleton beans, including those from factories, are instantiated in a thread-safe manner, preventing race conditions
during concurrent access.

- **Explicit BeanInstance State:** `BeanInstance` has been refactored to use static factory methods (`forProduct`, `forFactory`, `of`). This eliminates ambiguity by making the state of a bean instance (whether it holds a product, a factory, or both) explicit at the point of
creation.

- **Unified Factory Logic:** The `getFactoryProducedObject` method now centralizes the logic for obtaining a product from both `FactoryBean` instances and `factory-method` definitions. It also correctly handles the caching of singleton products.

This refactoring resolves fundamental issues in the IoC container's handling of factory-produced beans, leading to more predictable, robust, and thread-safe behavior.

48 of 107 new or added lines in 8 files covered. (44.86%)

245 existing lines in 7 files now uncovered.

15852 of 41518 relevant lines covered (38.18%)

0.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

43.3
/core/src/main/java/com/aspectran/core/component/bean/AnnotatedConfigParser.java


Source Not Available

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc