Reputation: 1465
Uses Apache Felix 4.2.1 iPOJO 1.11.0.
Requires programmatically create component instances when the user request. But i can not use none-static field in static factory method.
@Component
@Provides(specifications = {IProcessSearch.class})
public class ProcessSearch implements IProcessSearch {
...
@Requires(filter = "(factory.name=ProcessSearch)")
private Factory mProcessSearchFactory;
...
/**
* Factory methods for receive new component instance:
*/
public static ProcessSearch createInstance() {
return createInstance(null);
}
public static ProcessSearch createInstance(Properties pProperties) {
InstanceManager lInstanceManager = (InstanceManager) mProcessSearchFactory.createComponentInstance(pProperties);
return (ProcessSearch) lInstanceManager.getPojoObject();
}
1) If I understand correctly, then field with @Requires annotation can not be static. How to create factory method which take properties and receive new component instance?
2) Is it normal practice to do so?
Upvotes: 1
Views: 541
Reputation: 3192
Do do that, you need to provide your own creation strategy. This strategy is applied on the provided service (@Provides) and not on the consumer side (@Requires).
Upvotes: 1