spring-attic / spring-native

Spring Native is now superseded by Spring Boot 3 official native support
https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html
Apache License 2.0
2.74k stars 356 forks source link

Generate AOT task fails on aws sdk Class #1644

Closed shomub closed 2 years ago

shomub commented 2 years ago

Please see the below stack trace. This is reporrted during the generateAot tak while trying to build spring native image on an existing Java microservice

[6/7/2022 9:59 AM] Bagchi, Soumoya org.springframework.aot.context.bootstrap.generator.BeanDefinitionGenerationException: Failed to handle bean with name 'credentialsProvider' and type 'com.amazonaws.auth.AWSCredentialsProviderChain' at org.springframework.aot.context.bootstrap.generator.ApplicationContextAotProcessor.writeBeanDefinitions(ApplicationContextAotProcessor.java:138) at org.springframework.aot.context.bootstrap.generator.ApplicationContextAotProcessor.bootstrapMethod(ApplicationContextAotProcessor.java:104) at org.springframework.aot.context.bootstrap.generator.ApplicationContextAotProcessor.process(ApplicationContextAotProcessor.java:96) at org.springframework.aot.build.ContextBootstrapContributor.contribute(ContextBootstrapContributor.java:80) at org.springframework.aot.build.BootstrapCodeGenerator.generate(BootstrapCodeGenerator.java:91) at org.springframework.aot.build.BootstrapCodeGenerator.generate(BootstrapCodeGenerator.java:71) at org.springframework.aot.build.GenerateBootstrapCommand.call(GenerateBootstrapCommand.java:107) at org.springframework.aot.build.GenerateBootstrapCommand.call(GenerateBootstrapCommand.java:42) at picocli.CommandLine.executeUserObject(CommandLine.java:1953) at picocli.CommandLine.access$1300(CommandLine.java:145) at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2352) at picocli.CommandLine$RunLast.handle(CommandLine.java:2346) at picocli.CommandLine$RunLast.handle(CommandLine.java:2311) at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179) at picocli.CommandLine.execute(CommandLine.java:2078) at org.springframework.aot.build.GenerateBootstrapCommand.main(GenerateBootstrapCommand.java:112) Caused by: java.lang.IllegalArgumentException: Parameter of type ? is not supported at org.springframework.aot.context.bootstrap.generator.bean.support.ParameterWriter.writeParameterValue(ParameterWriter.java:175) at org.springframework.aot.context.bootstrap.generator.bean.support.ParameterWriter.lambda$writeAll$9(ParameterWriter.java:182) at org.springframework.aot.context.bootstrap.generator.bean.support.MultiCodeBlock.add(MultiCodeBlock.java:43) at org.springframework.aot.context.bootstrap.generator.bean.support.ParameterWriter.lambda$writeAll$10(ParameterWriter.java:181) at java.base/java.util.ArrayList.forEach(ArrayList.java:1541) at org.springframework.aot.context.bootstrap.generator.bean.support.ParameterWriter.writeAll(ParameterWriter.java:181) at org.springframework.aot.context.bootstrap.generator.bean.support.ParameterWriter.writeParameterValue(ParameterWriter.java:118) at org.springframework.aot.context.bootstrap.generator.bean.support.ParameterWriter.writeParameterValue(ParameterWriter.java:81) at org.springframework.aot.context.bootstrap.generator.bean.support.ParameterWriter.writeParameterValue(ParameterWriter.java:70) at org.springframework.aot.context.bootstrap.generator.bean.DefaultBeanRegistrationWriter.writeArgumentValue(DefaultBeanRegistrationWriter.java:265) at org.springframework.aot.context.bootstrap.generator.bean.DefaultBeanRegistrationWriter.handleArgumentValues(DefaultBeanRegistrationWriter.java:249) at org.springframework.aot.context.bootstrap.generator.bean.DefaultBeanRegistrationWriter.handleBeanDefinitionMetadata(DefaultBeanRegistrationWriter.java:230) at org.springframework.aot.context.bootstrap.generator.bean.DefaultBeanRegistrationWriter.initializeBeanDefinitionRegistrar(DefaultBeanRegistrationWriter.java:178) at org.springframework.aot.context.bootstrap.generator.bean.DefaultBeanRegistrationWriter.writeBeanRegistration(DefaultBeanRegistrationWriter.java:151) at org.springframework.aot.context.bootstrap.generator.bean.DefaultBeanRegistrationWriter.writeBeanRegistration(DefaultBeanRegistrationWriter.java:102) at org.springframework.aot.context.bootstrap.generator.ApplicationContextAotProcessor.writeBeanDefinitions(ApplicationContextAotProcessor.java:130) ... 15 more Caused by: java.lang.IllegalArgumentException: Parameter of type ? is not supported


basically this task fails: > Task :services:media-upload:generateAot FAILEDExecution failed for task ':services:media-upload:generateAot'.

Process 'command '/usr/local/Cellar/openjdk@11/11.0.9/libexec/openjdk.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

sdeleuze commented 2 years ago

Please provide a reproducer.

spring-projects-issues commented 2 years ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

shomub commented 2 years ago

Hello, PFA attached zip file which has the project that reproduces the issue. I have taken the sample project and added needed references to reproduce the same error on running the generateAot task

https://drive.google.com/drive/folders/1BhQzuxd8e6rO5mcrgFRb9B3amXYk3HxG?usp=sharing

Regards,

On Fri, Jun 24, 2022 at 12:50 PM Shomu Bagchi @.***> wrote:

Hi, Yes I am working on reproducing the issue with a sample poc as we cannot share the actual code. I will send it within another working day or two

Rgds

On Fri, Jun 24, 2022, 5:31 AM Spring Projects Issues < @.***> wrote:

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

— Reply to this email directly, view it on GitHub https://github.com/spring-projects-experimental/spring-native/issues/1644#issuecomment-1165389525, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIANQTPBOJQWWB56GJR7ITLVQV565ANCNFSM5ZADCZCQ . You are receiving this because you authored the thread.Message ID: @.*** .com>

sdeleuze commented 2 years ago

Thanks for providing the sample, I can indeed reproduce the issue. This should be supported but as we switch our focus from Spring Native to Spring Boot 3 native support, we should focus the advanced support on Spring Boot 3 side, so I think you should try with Spring Boot 3 snapshots if you see the same error or not, and if you do please open an issue with a reproducer on https://github.com/spring-projects/spring-framework/issues since the AOT engine lives in Spring Framework 6.

re-thc commented 2 years ago

Is there documentation on the spring boot 3 side? This this available there yet? Have checked the latest milestone and snapshot but can't find any docs on it. Thanks!

sdeleuze commented 2 years ago

Not yet, that's WIP.

shomub commented 2 years ago

complete.zip

Hi PFA this issue with Spring Boot 3/Java 17. I have attached the reproducer. Please advise if I need to open this as a separate issue

Exception in thread "main" org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'io.awspring.cloud.core.credentials.CredentialsProviderFactoryBean.BEAN_NAME' defined in null: Cannot register bean definition [Generic bean: class [io.awspring.cloud.core.credentials.CredentialsProviderFactoryBean]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodNames=null; destroyMethodNames=null] for bean 'io.awspring.cloud.core.credentials.CredentialsProviderFactoryBean.BEAN_NAME' since there is already [Generic bean: class [com.amazonaws.auth.AWSCredentialsProviderChain]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodNames=null; destroyMethodNames=null] bound. at org.springframework.beans.factory.support.DefaultListableBeanFactory.registerBeanDefinition(DefaultListableBeanFactory.java:1004) at io.awspring.cloud.core.config.AmazonWebserviceClientConfigurationUtils.registerCredentialsProviderIfNeeded(AmazonWebserviceClientConfigurationUtils.java:169) at io.awspring.cloud.core.config.AmazonWebserviceClientConfigurationUtils.getAmazonWebserviceClientBeanDefinition(AmazonWebserviceClientConfigurationUtils.java:97) at io.awspring.cloud.core.config.AmazonWebserviceClientConfigurationUtils.registerAmazonWebserviceClient(AmazonWebserviceClientConfigurationUtils.java:81) at io.awspring.cloud.context.config.annotation.ContextResourceLoaderConfiguration$Registrar.registerBeanDefinitions(ContextResourceLoaderConfiguration.java:58) at org.springframework.context.annotation.ImportBeanDefinitionRegistrar.registerBeanDefinitions(ImportBeanDefinitionRegistrar.java:86) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.lambda$loadBeanDefinitionsFromRegistrars$1(ConfigurationClassBeanDefinitionReader.java:384) at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:383) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:156) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:128) at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:366) at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:262) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:344) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:115) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:755) at org.springframework.context.support.GenericApplicationContext.refreshForAotProcessing(GenericApplicationContext.java:408) at org.springframework.context.aot.ApplicationContextAotGenerator.generateApplicationContext(ApplicationContextAotGenerator.java:49) at org.springframework.boot.AotProcessor.performAotProcessing(AotProcessor.java:150) at org.springframework.boot.AotProcessor.process(AotProcessor.java:111) at org.springframework.boot.AotProcessor.main(AotProcessor.java:220)

Task :generateAotSources FAILED

wilkinsona commented 2 years ago

@shomub Your problem doesn't appear to have anything to do with Spring Native or Spring Boot's AOT and Native support. It fails to start without any AOT processing due to it containing two beans named io.awspring.cloud.core.credentials.CredentialsProviderFactoryBean.BEAN_NAME. You can see this for yourself if you comment out the org.graalvm.buildtools.native and org.springframework.experimental.aot plugins and run ./gradlew bootRun. BTW, you shouldn't be using the org.springframework.experimental.aot plugin with Spring Boot 3.

It appears to be a problem with io.awspring.cloud:spring-cloud-starter-aws.

shomub commented 2 years ago

Thank you for the clarification Andy. I was just trying to reproduce issue #1644 with Spring Boot 3 or have it work. Do you have a recommendation for what version of the aot plugin to use with Spring Boot 3? and/or a specific version of the cloud-starter-aws for this ?

On Tue, Jul 26, 2022 at 10:56 AM Andy Wilkinson @.***> wrote:

@shomub https://github.com/shomub Your problem doesn't appear to have anything to do with Spring Native or Spring Boot's AOT and Native support. It fails to start without any AOT processing due to it containing two beans named io.awspring.cloud.core.credentials.CredentialsProviderFactoryBean.BEAN_NAME. You can see this for yourself if you comment out the org.graalvm.buildtools.native and org.springframework.experimental.aot plugins and run ./gradlew bootRun. BTW, you shouldn't be using the latter with Spring Boot 3.

It appears to be a problem with io.awspring.cloud:spring-cloud-starter-aws .

— Reply to this email directly, view it on GitHub https://github.com/spring-projects-experimental/spring-native/issues/1644#issuecomment-1195592934, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIANQTI4GU26IZBUJFBBK23VV74CHANCNFSM5ZADCZCQ . You are receiving this because you were mentioned.Message ID: @.*** com>

wilkinsona commented 2 years ago

Do you have a recommendation for what version of the aot plugin to use with Spring Boot 3?

Boot includes its own. Applying org.graalvm.buildtools.native is sufficient to activate it.

and/or a specific version of the cloud-starter-aws for this

I don't know. That's a question for the maintainers of https://github.com/awspring/spring-cloud-aws.

sdeleuze commented 2 years ago

Superseded by https://github.com/awspring/spring-cloud-aws/issues/468.

shomub commented 2 years ago

Hi, Yes I am working on reproducing the issue with a sample poc as we cannot share the actual code. I will send it within another working day or two

Rgds

On Fri, Jun 24, 2022, 5:31 AM Spring Projects Issues < @.***> wrote:

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

— Reply to this email directly, view it on GitHub https://github.com/spring-projects-experimental/spring-native/issues/1644#issuecomment-1165389525, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIANQTPBOJQWWB56GJR7ITLVQV565ANCNFSM5ZADCZCQ . You are receiving this because you authored the thread.Message ID: @.*** com>