You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by CLEMENT Jean-Philippe <je...@fr.thalesgroup.com> on 2013/06/03 15:34:03 UTC
Karaf 2.3.0 blueprint static factory bug
Dear Karaf team,
I have a problem with blueprint static factories.
I made a class I use as a static factory:
<bean id="testfactory" class="test.TestFactory" factory-method="staticFactory"/>
Then I try to inject testfactory to another bean as an argument:
<bean id="testbean" class="test.TestBean">
<argument ref="testfactory"/>
</bean>
The factory class is like this:
public final class TestFactory implements TestInterface {
private static final TestInterface FACTORY= new TestFactory();
private TestFactory() {}
public TestInterface staticFactory() {
return FACTORY;
}
The TestBean constructor like that:
public final class TestBean {
public TestBean(final TestInterface test) { ...}
}
This fails stating that no constructor can match. However:
* if I add a TestBean constructor taking an Object as argument, this test succeeds
* if I construct a bean implementing TestInterface, the constructor (taking TestInterface) is found.
I don't know what can be the problem. Is this kind of trouble already known?
PS: TestInterface is in fact using generics
Cheers,
JP
[@@ OPEN @@]
RE: Karaf 2.3.0 blueprint static factory bug
Posted by CLEMENT Jean-Philippe <je...@fr.thalesgroup.com>.
More info,
I succeeded in fixing this issue changing the generic type :S
To be more precise,
The TestBean constructor is like this:
public TestBean(final TestInterface<? Extends Component> test) { ...}
If the implementation is this way, blueprint find the test bean constructor:
public TestInterface<Component> staticFactory() { ... }
But, if the implementation is this way, blueprint fails to find test bean constructor:
public TestInterface<JPanel> staticFactory() { ... }
Note that this bug is not related to the static factory as I reproduced this issue with direct bean construction (i.e. changing private constructor to public removing "factory-method" option from blueprint.
So it seems to be a generics related problem. Any idea?
Cheers,
Jean-Philippe
[@@ OPEN @@]
De : CLEMENT Jean-Philippe [mailto:jean-philippe.clement@fr.thalesgroup.com]
Envoyé : lundi 3 juin 2013 15:34
À : user@karaf.apache.org
Objet : Karaf 2.3.0 blueprint static factory bug
Dear Karaf team,
I have a problem with blueprint static factories.
I made a class I use as a static factory:
<bean id="testfactory" class="test.TestFactory" factory-method="staticFactory"/>
Then I try to inject testfactory to another bean as an argument:
<bean id="testbean" class="test.TestBean">
<argument ref="testfactory"/>
</bean>
The factory class is like this:
public final class TestFactory implements TestInterface {
private static final TestInterface FACTORY= new TestFactory();
private TestFactory() {}
public TestInterface staticFactory() {
return FACTORY;
}
The TestBean constructor like that:
public final class TestBean {
public TestBean(final TestInterface test) { ...}
}
This fails stating that no constructor can match. However:
* if I add a TestBean constructor taking an Object as argument, this test succeeds
* if I construct a bean implementing TestInterface, the constructor (taking TestInterface) is found.
I don't know what can be the problem. Is this kind of trouble already known?
PS: TestInterface is in fact using generics
Cheers,
JP
[@@ OPEN @@]