Skip to content

@Bean overriding does not pick up metadata from most specific method [SPR-10992] #15620

Closed
@spring-projects-issues

Description

@spring-projects-issues

Benoit Lacelle opened SPR-10992 and commented

While overrding a Javaconfig Bean by extending the original @Configuration class, I would like to add a @DependsOn for the new Bean definition.

However, this depends-on seems not to be taken in account. here is a TestCase reproducing my issues:

public class SpringTest {

	@Test
	public void testDependsOnTakenInAccount() {
		AnnotationConfigApplicationContext ctx2 = new AnnotationConfigApplicationContext(AConfig.class, CConfig.class);
		Assert.assertEquals("overriden", ctx2.getBean("bean"));
	}

	@Configuration
	public static class AConfig {

		@Bean
		public Object bean() {
			return "not overriden";
		}

	}

	@Configuration
	public static class CConfig extends AConfig {

		protected boolean isInitialized = false;

		@Bean
		public Void doInit() {
			isInitialized = true;

			return null;
		}

		@Bean
		@DependsOn("doInit")
		public Object bean() {
			if (!isInitialized) {
				throw new RuntimeException("Not initialized");
			}

			return "overriden";
		}

	}

}

Is this an expected behavior? If yes, how can I add dependency while overriding a bean?


Affects: 3.2.3

Issue Links:

0 votes, 5 watchers

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