Skip to content

Inconsistency between property Injection and setter Injection causes NoUniqueBeanDefinitionException [SPR-14179] #18750

Closed
@spring-projects-issues

Description

@spring-projects-issues

Christian Hersevoort opened SPR-14179 and commented

The case is as follows:

Beans:

  • MyParentBean
  • MyChildBeanA implements MyChildBean
  • MyChildBeanB implements MyChildBean

XML configuration:

<bean id="myChildBeanA" class="com.hersevoort.java.test.MyChildBeanA">
</bean>
<bean id="myChildBeanB" class="com.hersevoort.java.test.MyChildBeanB">
</bean>
<bean id="myParentBean" class="com.hersevoort.java.test.MyParentBean">
	<property name="myChild" ref="myChildBeanB"/>
</bean>

Case #1: This works:

public class MyParentBean
{
	private MyChildBean myChild;

	@Inject
	public void setMyChild(MyChildBean myChild)
	{
		this.myChild = myChild;
	}
}

Case #2: This doesn't work:

public class MyParentBean
{
	@Inject
	private MyChildBean myChild;
}

I expect Spring to handle both cases exactly the same, but Case #2 throws an unexpected NoUniqueBeanDefinitionException. (see attachment)

Am I wrong to assume this is a bug?


Affects: 4.2.1, 4.2.5, 4.3 RC1

Attachments:

Issue Links:

Metadata

Metadata

Assignees

Labels

status: declinedA suggestion or change that we don't feel we should currently apply

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions