I have an error which I've never seen before in Spring(I'm newbie:D). I have 3 classes(MainDao
, DaoV1
, DaoV2
) which implement same interface(Repo
) MainDao
has two constructor arguments which are DaoV1
and DaoV2
. The creation of DaoV1 and DaoV2 is totally fine, but when I add MainDao
bean in xml, I get the error below! What is the problem?
Error message:
org.springframework.beans.factory.access.BootstrapException:
Unable to initialize group definition. Group resource name
[classpath*:beanRefContext_SomeService.xml], factory key
[applicationContext_SomeService]; nested exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'applicationContext_SomeService'
defined in URL [file:/opt/ibm/AppSrv70_1/installedApps/cell01/SomeService.ear/SomeServiceWebV2.war/WEB-INF/classes/beanRefContext_SomeService.xml]: Instantiation of bean failed;
nested exception is org.springframework.beans.BeanInstantiationException:
Could not instantiate bean class [org.springframework.context.support.ClassPathXmlApplicationContext]:
Constructor threw exception; nested exception
is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'mainDao' defined in class path resource
[SomeServiceDaoEjb-context.xml]: Unsatisfied dependency expressed through
constructor argument with index 0 of type [com.example.dao.DaoV1]: Could
not convert constructor argument value of type [$Proxy197] to required type
[com.example.dao.DaoV2]: Failed to convert value of type '$Proxy197 implementing com.example.spi.Repo,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised'
to required type 'com.example.dao.DaoV1'; nested exception is java.lang.IllegalStateException:
Cannot convert value of type [$Proxy197 implementing com.example.spi.Repo,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised]
to required type [com.example.dao.DaoV1]: no matching editors or conversion strategy found
Repo.class
public interface Repo {
Item retrieve(Integer var1, Integer var2);
}
DaoV1.class
public class DaoV1 implements Repo {
final ClassA arg1;
private ClassB arg2;
public DaoV1(ClassA arg1, ClassB arg2) {
this.arg1 = arg1;
this.arg2 = arg2;
}
public Item retrieve(Integer var1, Integer var2) {
// arg.get() ....
}
}
DaoV2.class
public class DaoV2 implements Repo {
private SampleService service;
public DaoV2(SampleService service) {
this.service = service;
}
public Item retrieve(Integer var1, Integer var2) {
// service.get() ....
}
}
MainDao.class
public class MainDao implements Repo {
private DaoV1 v1;
private DaoV2 v2;
public MainDao(DaoV1 v1, DaoV2 v2) {
this.v1 = v1;
this.v2 = v2;
}
public Item retrieve(Integer var1, Integer var2) {
//
}
}
Beans
<bean id="v1" class="com.example.dao.DaoV1">
<constructor-arg ref="classAParam" />
<constructor-arg ref="classBParam" />
</bean>
<bean id="v2" class="com.example.dao.DaoV2">
<constructor-arg ref="service" />
</bean>
<bean id="maindao" class="com.example.dao.MainDao">
<constructor-arg ref="v1" />
<constructor-arg ref="v2" />
</bean>