spring not able to resolve constructor
I am sure this issue would be similar to one on some other thread posted. Just point me to that thread if any.
Query: I have a class that can be constructed by two ways-
class MyClass {
/*1st constructor*/
MyClass() {} //Creates a new instance
/*2nd constructor*/
MyClass(ResultSet rs) {} //ResultSet object holds row from database; This way MyClass can be created from its existing Db entry
}
Following is my bean defination to load it.
bean.xml :
<bean id="myClass" class="com.package.MyClass"
scope="prototype"/>
and following are the two calls:
1st call
m_ctx.getBean("myClass", null); // intended to call 1st constructor
2nd call
m_ctx.getBean("myClass", new Object[] {rs}); // intended to call 2nd constructor
// m_ctx is instance of org.springframework.context.ApplicationContext
I can load 'myClass' instance from db by calling 2nd call or I can create a new instance of 'myClass' by making 1st call, but....
If i create a new instance of 'myClass' and load existing 'myClass' with same ApplicationContext, m_ctx, i am not able to...
Ill explain this..
...
//somewhere in the code
MyClass m1 = m_ctx.getBean("myClass", null); // create a new 'myClass'
...
// in same code with same instance of m_ctx
MyClass m2 = m_ctx.getBean("myClass", new Object[] {rs}); // load 'myClass' from rs
This call is not able to resolve constructor correctly and it calls 1st constructor instead 2nd. This 1st constructor was found cached bean definition of 'myClass', and during 2nd bean call it returned the cached constructor instead of re-resolving the constructor.
All this is happening in org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBeanInstance(Stri ng beanName, RootBeanDefinition mbd, Object[] args) call
If above explanation is making any sense then please let me know what is going wrong here?