Skip to content

Clarify @Bean(autowire=NO) [SPR-14282] #18854

Closed
@spring-projects-issues

Description

@spring-projects-issues

Rob Winch opened SPR-14282 and commented

Given the following classes:

public class Foo {

	@Autowired
	Bar bar;
}

public class Bar { }

@Configuration
public class Config {

	@Bean
	public Foo foo() {
		return new Foo();
	}

	@Bean
	public Bar bar() {
		return new Bar();
	}
}

It is not logical that the following test will fail since the autowire attribute on @Bean is by default NO:

try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext()) {
	ctx.register(Config.class);
	ctx.refresh();

	Foo foo = ctx.getBean(Foo.class);

	assertThat(foo.bar, nullValue());
}

Affects: 3.2.17, 4.2.6, 4.3 RC2

Issue Links:

Referenced from: commits 7da1295, 98eaf05, a0a2a33

Backported to: 4.2.7, 3.2.18

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: taskA general task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions