Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AOT-generated code does not consider by-type RuntimeBeanReferences #28841

Closed
mp911de opened this issue Jul 19, 2022 · 0 comments
Closed

AOT-generated code does not consider by-type RuntimeBeanReferences #28841

mp911de opened this issue Jul 19, 2022 · 0 comments
Assignees
Labels
theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Milestone

Comments

@mp911de
Copy link
Member

mp911de commented Jul 19, 2022

Given the following code to register a BeanDefinition:

registry.registerBeanDefinition("my-bean-consumer", BeanDefinitionBuilder.rootBeanDefinition(BeanConsumer.class)
		.addConstructorArgValue(new RuntimeBeanReference(Bean.class))
		.getBeanDefinition());

then generating AOT code results in:

Class<?> beanType = BeanConsumer.class;
RootBeanDefinition beanDefinition = new RootBeanDefinition(beanType);
beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(0, new RuntimeBeanReference("com.example.demo.Bean"));
beanDefinition.setInstanceSupplier(InstanceSupplier.of(BeanConsumer__BeanDefinitions::getMybeanconsumerInstance));

The constructor reference value now points to a bean named com.example.demo.Bean instead of using the type reference com.example.demo.Bean. Running that code leads to:

BeanCreationException: Error creating bean with name 'my-bean-consumer': Cannot resolve reference to bean 'com.example.demo.Bean' while setting constructor argument

Additional code used to reproduce the issue:

public class Bean {
}

public class BeanConsumer {

	public BeanConsumer(Bean bean) {
	}
}

public class ReproducerRegistrar implements ImportBeanDefinitionRegistrar {

	@Override
	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry, BeanNameGenerator importBeanNameGenerator) {

		registry.registerBeanDefinition("my-bean", BeanDefinitionBuilder.rootBeanDefinition(Bean.class)
				.getBeanDefinition());

		registry.registerBeanDefinition("my-bean-consumer", BeanDefinitionBuilder.rootBeanDefinition(BeanConsumer.class)
				.addConstructorArgValue(new RuntimeBeanReference(Bean.class))
				.getBeanDefinition());

	}
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 19, 2022
@sdeleuze sdeleuze added this to the 6.0.0-M6 milestone Jul 19, 2022
@sdeleuze sdeleuze added type: bug A general bug theme: aot An issue related to Ahead-of-time processing and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 19, 2022
@snicoll snicoll self-assigned this Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants