oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
19.96k stars 1.6k forks source link

native-image not honoring abstract="true" and constructor overloading in the spring context.xml #9185

Open bill-reck opened 5 days ago

bill-reck commented 5 days ago

(1) The native-image Spring context parser is erroneously trying to construct template beans where abstract="true" resulting in a runtime error. Please see the attached myContext.xml file.

(2) Also another lesser issue: The native-image Spring context parser is unable to handle bean definitions that use overloaded constructors with multiple arguments. Please see the attached myContext.xml and Example2.java files.

(I've included two issues as they are demonstrated with the same project files)

Steps to reproduce the issue issue (1) 1) assemble a project using the attached files 2) compile the project using mvn -Pnative -DskipTests package 3) Run the generated image

issue (2) 1) assemble a project using the attached files 2) uncomment the example2 bean in the myContext.xml file 3) attempt to compile the project using mvn -Pnative -DskipTests package

Describe GraalVM and your environment: Using the maven plugin in the pom.xml:

org.graalvm.buildtools native-maven-plugin 0.10.2

issues_project.gz

More details issue (1) runtime failure:

Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'example1Template': Invalid property 'value' of bean class [java.lang.Object]: Bean property 'value' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1722) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1436) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:599) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:962) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) at ww.pop.graalvm.Main.main(Main.java:12) C

issue (2) compile time failure:

Exception in thread "main" java.lang.IllegalStateException: No constructor or factory method candidate found for Root bean: class [ww.pop.graalvm.Example2]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodNames=null; destroyMethodNames=null; defined in class path resource [myContext.xml] and argument types [java.lang.String, java.lang.String] at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorOrFactoryMethod(ConstructorResolver.java:987) at org.springframework.beans.factory.support.RegisteredBean.resolveConstructorOrFactoryMethod(RegisteredBean.java:218) at org.springframework.beans.factory.support.RegisteredBean.resolveInstantiationDescriptor(RegisteredBean.java:228) at org.springframework.util.function.SingletonSupplier.get(SingletonSupplier.java:106) at org.springframework.beans.factory.aot.DefaultBeanRegistrationCodeFragments.getTarget(DefaultBeanRegistrationCodeFragments.java:86) at org.springframework.beans.factory.aot.BeanDefinitionMethodGenerator.generateBeanDefinitionMethod(BeanDefinitionMethodGenerator.java:85) at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.lambda$generateRegisterBeanDefinitionsMethod$2(BeanRegistrationsAotContribution.java:90) at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721) at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.generateRegisterBeanDefinitionsMethod(BeanRegistrationsAotContribution.java:88) at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.lambda$applyTo$1(BeanRegistrationsAotContribution.java:73) at org.springframework.aot.generate.GeneratedMethod.(GeneratedMethod.java:54) at org.springframework.aot.generate.GeneratedMethods.add(GeneratedMethods.java:112) at org.springframework.aot.generate.GeneratedMethods.add(GeneratedMethods.java:89) at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.applyTo(BeanRegistrationsAotContribution.java:72) at org.springframework.context.aot.BeanFactoryInitializationAotContributions.applyTo(BeanFactoryInitializationAotContributions.java:78) at org.springframework.context.aot.ApplicationContextAotGenerator.lambda$processAheadOfTime$0(ApplicationContextAotGenerator.java:58) at org.springframework.context.aot.ApplicationContextAotGenerator.withCglibClassHandler(ApplicationContextAotGenerator.java:67) at org.springframework.context.aot.ApplicationContextAotGenerator.processAheadOfTime(ApplicationContextAotGenerator.java:53) at org.springframework.context.aot.ContextAotProcessor.performAotProcessing(ContextAotProcessor.java:106) at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:84) at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:49) at org.springframework.context.aot.AbstractAotProcessor.process(AbstractAotProcessor.java:82) at org.springframework.boot.SpringApplicationAotProcessor.main(SpringApplicationAotProcessor.java:80)

bill-reck commented 5 days ago

Both of these constructs work correctly with generic Spring

oubidar-Abderrahim commented 4 days ago

Hi @bill-reck , Thank you for reaching out about this issue, please share a reproducer code to this issue in a Github repo that we can clone, also specify what it the exact version of GraalVM used. Thank you

bill-reck commented 2 days ago

Hi, Thanks for your reply.

I'm using version 0.10.2 of the native-maven-plugin which pulls in version 22.3.3 of the compiler.

I claim that adding the following three lines to any Spring context.xml file will result in a native image runtime error, regardless of the GraalVM version:

     <bean id="exampleTemplate" abstract="true">
              <property name="value" value="foo" />
     </bean>

This construct has been part of Spring for almost 2 decades.

thanks

fniephaus commented 2 days ago

@sdeleuze any idea what is going on here?