Skip to content

Document how to configure FactoryBean with a configurable target with AOT #30434

Closed
@DanielThomas

Description

@DanielThomas

After addressing #30410 we still see failures wiring our GRPC client beans. The registration is:

  /**
   * Get the bean definition for 'grpcClient_myclient'.
   */
  public static BeanDefinition getGrpcClientmyclientBeanDefinition() {
    Class<?> beanType = StubFactoryBean.class;
    RootBeanDefinition beanDefinition = new RootBeanDefinition(beanType);
    beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(0, MyClientBlockingStub.class);
    beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(1, "myclient");
    beanDefinition.addQualifier(new AutowireCandidateQualifier("com.example.demo.GrpcSpringClient", "myclient"));
    beanDefinition.setInstanceSupplier(getGrpcClientmyclientInstanceSupplier());
    return beanDefinition;
  }

With AOT enabled the application fails to start with:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in com.example.demo.DemoApplication$RequiresGrpcClient required a bean of type 'com.example.demo.MyClientBlockingStub' that could not be found.

The injection point has the following annotations:
	- @com.example.demo.GrpcSpringClient("myclient")

Without AOT, the bean is found successfully via:

doGetBeanNamesForType:584, DefaultListableBeanFactory (org.springframework.beans.factory.support)
getBeanNamesForType:540, DefaultListableBeanFactory (org.springframework.beans.factory.support)
beanNamesForTypeIncludingAncestors:260, BeanFactoryUtils (org.springframework.beans.factory)
findAutowireCandidates:1581, DefaultListableBeanFactory (org.springframework.beans.factory.support)
doResolveDependency:1380, DefaultListableBeanFactory (org.springframework.beans.factory.support)
resolveDependency:1337, DefaultListableBeanFactory (org.springframework.beans.factory.support)
resolveAutowiredArgument:885, ConstructorResolver (org.springframework.beans.factory.support)
createArgumentArray:789, ConstructorResolver (org.springframework.beans.factory.support)
autowireConstructor:245, ConstructorResolver (org.springframework.beans.factory.support)
autowireConstructor:1352, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
createBeanInstance:1189, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
doCreateBean:560, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
createBean:520, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
lambda$doGetBean$0:326, AbstractBeanFactory (org.springframework.beans.factory.support)
getObject:-1, AbstractBeanFactory$$Lambda$286/0x00000008011a2070 (org.springframework.beans.factory.support)
getSingleton:234, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support)
doGetBean:324, AbstractBeanFactory (org.springframework.beans.factory.support)
getBean:200, AbstractBeanFactory (org.springframework.beans.factory.support)
preInstantiateSingletons:973, DefaultListableBeanFactory (org.springframework.beans.factory.support)
finishBeanFactoryInitialization:917, AbstractApplicationContext (org.springframework.context.support)
refresh:584, AbstractApplicationContext (org.springframework.context.support)
refresh:732, SpringApplication (org.springframework.boot)
refreshContext:434, SpringApplication (org.springframework.boot)
run:310, SpringApplication (org.springframework.boot)
run:1304, SpringApplication (org.springframework.boot)
run:1293, SpringApplication (org.springframework.boot)
main:17, DemoApplication (com.example.demo)

However, with AOT FactoryBean.getObjectType() isn't even called on the StubFactoryBean.

Example project:

https://github.com/DanielThomas/spring-aot-issues/tree/dannyt/factory-beans

Run and note the failure:

./gradlew bootJar && java -Dspring.aot.enabled=true -jar build/libs/demo-0.0.1-SNAPSHOT.jar

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)theme: aotAn issue related to Ahead-of-time processingtype: documentationA documentation task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions