Hi,

Am 02.07.2012 um 10:14 schrieb Meriç Taze:

> Hi all,
> 
> I am trying to create a new instance of my class from felix console. Hence,
> I'm using Component annotation like this:
> 
> @Component(configurationFactory = true, policy =
> ConfigurationPolicy.REQUIRE, metatype = true)
> 
> and this works well. I can create new instance by using Configuration tab
> of felix console. Now I also want to create
> new instance of my class inside my java code. Thus, I tried to use
> 
> @Component(factory = "org.apache.test.MyClassFactory")
> 
> This is also work. However, I want both of these functionalities for my
> class. Therefore, I add to top of my class definition
> 
> @Component(configurationFactory = true, factory =
> "org.apache.test.MyClassFactory", policy = ConfigurationPolicy.REQUIRE,
> metatype = true)
> 
> and it did not work as I expected. My question is how can achieve to create
> my class instances using both felix
> console and java code. I cannot succeed it by using
> both configurationFactory and factory. Is there any other way?

By the spec, this is not possible because factory configurations cannot be used 
to created instances of factory components. IIRC this is explicitly stated in 
the spec.

The Felix implementation currently supports this non-compliant behaviour. But 
(a) you have to explicitly enable it and (b) you create a hidden implementation 
dependency. So I would discourage from using it.

Rather I would solve the problem as follows:

  * Create a regular factory component (your second example)
  * Create another component having a service reference to the
     ComponentFactory service of the factory component. This
     second component has instances created for factory
     configuration. This component manages factory component
     instances for the factory configurations.

HTH 

Regards
Felix

> 
> Thanks.

Reply via email to