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

MessagingAnnotationBeanPostProcessor: Code generation does not support org.springframework.beans.factory.support.DefaultListableBeanFactory #8703

Closed
mmoayyed opened this issue Aug 15, 2023 · 4 comments

Comments

@mmoayyed
Copy link

mmoayyed commented Aug 15, 2023

In what version(s) of Spring Integration are you seeing this issue?

6.2.0-M1

Describe the bug

During AOT processing, the Gradle processAot fails with the following:

Caused by: java.lang.IllegalArgumentException: Code generation does not support org.springframework.beans.factory.support.DefaultListableBeanFactory
        at org.springframework.beans.factory.aot.BeanDefinitionPropertyValueCodeGenerator.generateCode(BeanDefinitionPropertyValueCodeGenerator.java:134)
        at org.springframework.beans.factory.aot.BeanDefinitionPropertyValueCodeGenerator.generateCode(BeanDefinitionPropertyValueCodeGenerator.java:99)
        ... 31 more

While debugging through the call stack, I can see the bean definition that is being processed is MessagingAnnotationBeanPostProcessor and it contains the following constructor:

public MessagingAnnotationBeanPostProcessor(BeanDefinitionRegistry registry,
			Map<Class<? extends Annotation>, MethodAnnotationPostProcessor<?>> postProcessors) {

		this.registry = registry;
		this.postProcessors = postProcessors;
}

The stacktrace shows:

        at org.springframework.beans.factory.aot.BeanDefinitionPropertyValueCodeGenerator.generateCode(BeanDefinitionPropertyValueCodeGenerator.java:102)
        at org.springframework.beans.factory.aot.BeanDefinitionPropertiesCodeGenerator.generateValue(BeanDefinitionPropertiesCodeGenerator.java:220)
        at org.springframework.beans.factory.aot.BeanDefinitionPropertiesCodeGenerator.lambda$addConstructorArgumentValues$3(BeanDefinitionPropertiesCodeGenerator.java:171)
        at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:986)
        at java.base/java.util.Collections$UnmodifiableMap.forEach(Collections.java:1707)
        at org.springframework.beans.factory.aot.BeanDefinitionPropertiesCodeGenerator.addConstructorArgumentValues(BeanDefinitionPropertiesCodeGenerator.java:170)

Debugger shows that when calling addConstructorArgumentValues, the constructor argument BeanDefinitionRegistry registry eventually leads to this error.

To Reproduce

./gradlew clean build with Spring Boot 3.2 M1 and 6.2.0-M1.

Expected behavior

AOT build should complete successfully

Sample

Related issue: #8571

I'll put together a sample next.

@mmoayyed mmoayyed added status: waiting-for-triage The issue need to be evaluated and its future decided type: bug labels Aug 15, 2023
@artembilan artembilan added status: waiting-for-reporter Needs a feedback from the reporter and removed status: waiting-for-triage The issue need to be evaluated and its future decided labels Aug 15, 2023
@artembilan
Copy link
Member

Yeah... removed my comment: was blind enough to mix up with versions :shame:

So, yeah... The current version is like this:

		this.registry.registerBeanDefinition(
				Introspector.decapitalize(MessagingAnnotationBeanPostProcessor.class.getName()),
				BeanDefinitionBuilder.rootBeanDefinition(MessagingAnnotationBeanPostProcessor.class)
						.setRole(BeanDefinition.ROLE_INFRASTRUCTURE)
						.addConstructorArgValue(this.registry)
						.addConstructorArgValue(this.postProcessors)
						.getBeanDefinition());

And you claim that this BeanDefinitionRegistry is a wrong candidate for the ctor injection.

Will investigate what we can do...

Thank you!

@artembilan artembilan added in: core and removed status: waiting-for-reporter Needs a feedback from the reporter labels Aug 15, 2023
@artembilan artembilan added this to the 6.2.0-M2 milestone Aug 15, 2023
@artembilan
Copy link
Member

Have fixed that one, but now fails like this:

Exception in thread "main" java.lang.IllegalArgumentException: Failed to generate code for '{interface org.springframework.integration.annotation.Transformer=org.springframework.integration.config.TransformerAnnotationPostProcessor@99a78d7, interface org.springframework.integration.annotation.Splitter=org.sprin
gframework.integration.config.SplitterAnnotationPostProcessor@31da6b2e, interface org.springframework.integration.annotation.Router=org.springframework.integration.config.RouterAnnotationPostProcessor@61c76850, interface org.springframework.integration.annotation.Aggregator=org.springframework.integration.confi
g.AggregatorAnnotationPostProcessor@70242f38, interface org.springframework.integration.annotation.InboundChannelAdapter=org.springframework.integration.config.InboundChannelAdapterAnnotationPostProcessor@2a22ad2b, interface org.springframework.integration.annotation.BridgeFrom=org.springframework.integration.c
onfig.BridgeFromAnnotationPostProcessor@48c3205a, interface org.springframework.integration.annotation.BridgeTo=org.springframework.integration.config.BridgeToAnnotationPostProcessor@121c54fa, interface org.springframework.integration.annotation.Filter=org.springframework.integration.config.FilterAnnotationPostProcessor@4390f46e, interface org.springframework.integration.annotation.ServiceActivator=org.springframework.integration.config.ServiceActivatorAnnotationPostProcessor@7c6442c2}' with type java.util.HashMap<?, ?>
        at org.springframework.beans.factory.aot.BeanDefinitionPropertyValueCodeGenerator.generateCode(BeanDefinitionPropertyValueCodeGenerator.java:102)
        at org.springframework.beans.factory.aot.BeanDefinitionPropertiesCodeGenerator.generateValue(BeanDefinitionPropertiesCodeGenerator.java:220)
        at org.springframework.beans.factory.aot.BeanDefinitionPropertiesCodeGenerator.lambda$addConstructorArgumentValues$3(BeanDefinitionPropertiesCodeGenerator.java:171)
        at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721)
        at java.base/java.util.Collections$UnmodifiableMap.forEach(Collections.java:1553)
        at org.springframework.beans.factory.aot.BeanDefinitionPropertiesCodeGenerator.addConstructorArgumentValues(BeanDefinitionPropertiesCodeGenerator.java:170)
        at org.springframework.beans.factory.aot.BeanDefinitionPropertiesCodeGenerator.generateCode(BeanDefinitionPropertiesCodeGenerator.java:122)

Turns out the AOT code generation doesn't like a Map as property/ctor argument for bean definitions.

Not sure yet how to propagate it from the MessagingAnnotationPostProcessor to the MessagingAnnotationBeanPostProcessor...

@mmoayyed
Copy link
Author

Thank you very much for looking into this issue!

@rishiraj88
Copy link

Interesting! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants