I am migrating from Spring 3 to Spring 4 and everything worked fine on Spring 3 so something must have been changed in Spring 4 in the autowiring interfaces with generics.. I am attaching simple sample application reproducing the problem.
The exception
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'firstService': Injection of autowired
dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire field: private my.package.SecondService
my.package.FirstServiceImpl.secondService; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type [my.package.SecondService] found for
dependency: expected at least 1 bean which qualifies as autowire
candidate for this dependency. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true),
@org.springframework.beans.factory.annotation.Qualifier(value=secondService)}
at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at
org.apache.cxf.transport.servlet.CXFServlet.createSpringContext(CXFServlet.java:151)
at
org.apache.cxf.transport.servlet.CXFServlet.loadBus(CXFServlet.java:74)
at
org.apache.cxf.transport.servlet.CXFNonSpringServlet.init(CXFNonSpringServlet.java:77)
Classes
@Component("firstService")
public class FirstServiceImpl extends BaseService implements FirstService {
@Autowired
@Qualifier("secondService")
private SecondService<Shoes, ShoesPayableThingForm> secondService;
}
public interface SecondService<T extends PayableThing,S extends PayableThingForm<?>> {
}
@Component("secondService")
public class SecondServiceImpl extends BaseService implements SecondService<PayableThing,PayableThingForm<PayableThing>> {
}
public class Shoes implements PayableThingWithDiscount{
}
public interface PayableThingWithDiscount extends PayableThing{
}
public class ShoesPayableThingForm implements PayableThingForm<Shoes>{
}
public interface PayableThingForm<T extends PayableThing> {
}
public interface PayableThing {
}
After Spring debugging...
During autowiring Spring 4.2.6 Class ResolvableType returns false from method where it seems it should return true (I think so.. because SecondServiceImpl is not autowired due to this check)
Ted Kin opened SPR-14398 and commented
Problem background
I am migrating from Spring 3 to Spring 4 and everything worked fine on Spring 3 so something must have been changed in Spring 4 in the autowiring interfaces with generics.. I am attaching simple sample application reproducing the problem.
The exception
Classes
After Spring debugging...
During autowiring Spring 4.2.6 Class ResolvableType returns false from method where it seems it should return true (I think so.. because SecondServiceImpl is not autowired due to this check)
here:
with this parameters catched on debug:
To reproduce that error
In case u would be so kind to reproduce this error, it is enough to run this junit:
Affects: 4.2.6
Attachments:
3 votes, 3 watchers