Skip to content

AOT-generated bean definition does not consider name of RuntimeBeanReference using name and type #35913

@mp911de

Description

@mp911de

Bean definitions using RuntimeBeanReference configured with both, a bean name and type, are rendered as RuntimeBeanReference(Class) instead of RuntimeBeanReference(String, Class)

Reproducer:

public class Reproducer implements ImportBeanDefinitionRegistrar {

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

		registry.registerBeanDefinition("bar1", new RootBeanDefinition(Bar.class));
		registry.registerBeanDefinition("bar2", new RootBeanDefinition(Bar.class));

		AbstractBeanDefinition foo = BeanDefinitionBuilder.rootBeanDefinition(Foo.class)
				.addConstructorArgValue(new RuntimeBeanReference("bar1", Bar.class))
				.getBeanDefinition();

		registry.registerBeanDefinition("foo", foo);
	}

	record Foo(Bar bar) {
	}

	public static class Bar {}
}

Generated AOT Bean Definitions:

@Generated
public class Reproducer__BeanDefinitions {
  /**
   * Bean definitions for {@link Reproducer.Foo}.
   */
  @Generated
  public static class Foo {
    /**
     * Get the bean instance supplier for 'foo'.
     */
    private static BeanInstanceSupplier<Reproducer.Foo> getFooInstanceSupplier() {
      return BeanInstanceSupplier.<Reproducer.Foo>forConstructor(Reproducer.Bar.class)
              .withGenerator((registeredBean, args) -> new Reproducer.Foo(args.get(0)));
    }

    /**
     * Get the bean definition for 'foo'.
     */
    public static BeanDefinition getFooBeanDefinition() {
      RootBeanDefinition beanDefinition = new RootBeanDefinition(Reproducer.Foo.class);
      beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(0, new RuntimeBeanReference(Reproducer.Bar.class));
      beanDefinition.setInstanceSupplier(getFooInstanceSupplier());
      return beanDefinition;
    }
  }

Original report: spring-projects/spring-data-jpa#4105

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)theme: aotAn issue related to Ahead-of-time processingtype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions