Skip to content

Return type prediction for generic factory method fails if type conversion of method arguments is necessary [SPR-10411] #15044

Closed
@spring-projects-issues

Description

@spring-projects-issues

Dmitry Katsubo opened SPR-10411 and commented

Overview

The following scenario does not work.

XML
<bean name="mocksControl" class="org.easymock.EasyMock" factory-method="createStrictControl" />

<bean id="transactionOperations"
	factory-bean="mocksControl"
	factory-method="createMock"
	p:class="org.springframework.transaction.support.TransactionOperations" />

<bean id="jdbcOperations"
	factory-bean="mocksControl"
	factory-method="createMock"
	p:class="org.springframework.jdbc.core.JdbcOperations" />
Java
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:/my-context.xml")
public class MyTest {

	@Autowired
	private TransactionOperations		transactionOperations;

	@Autowired
	private IMocksControl			mocksControl;
...
}
Trace
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.XXX.transactionOperations; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.transaction.support.TransactionOperations] 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)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
	... 41 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.transaction.support.TransactionOperations] 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)}
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:986)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:856)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
	... 43 more

Analysis

See comments below.


Affects: 3.2.2

Attachments:

Issue Links:

Referenced from: commits 8fdc7d4, b913578, b305f00, e86e182, 8b1927f

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions