I have a Java class which I’m using to instantiate multiple objects for use in test cases.
In my spring configuration for invoking this class I have something like the following:
<bean id="myClass" class="com.foo.MyClass">
<constructor-arg ref="myBean" />
</bean>
<bean id="myBeanA" factory-bean="myClass" factory-method="getA" />
<bean id="myBeanB" factory-bean="myClass" factory-method="getB" />
<bean id="myBeanC" factory-bean="myClass" factory-method="getC" />
MyClass does not extend anything.
My issue is that calling methods MyClass.getA() and MyClass.getB() works but MyClass.getC() does not and always throws a BeanCreationException: No factory method found getC()
None of the methods are static and all of them are public. Debugging through Spring jars I can see that when the bean for MyClass.getC() is created it doesn’t pick up the method when it does getLeafMethods(), but will find methods getA() and getB() and Object methods but none of the other methods in the class. Has anyone encountered a issue like this before or know why its unable to find all the methods in the class?
I cannot post the actual code but here is simpler version of it:
public class MyClass {
private A a;
private int i;
public MyClass(D param) {
//initialize here
}
public A getA() {
return a;
}
public B getB() {
return new B(i++);
}
//I could invoke this in a static way
//however the same issue occurs either way.
public C getC() {
return new C();
}
}
It seems there were 2 issues for me, one was a build issue which was cleared with blowing away and recreating my workspace. The second issue was in my case the type C was parametrized, and I needed to specify
new C<T>();instead of justnew C();. I was using a static method inside of C( C.makeC(Params...))to instantiate the object which I think caused the error. So I guess it was a type erasure issue that caused this. Thanks for the all the help!-Niru