Skip to content

Excluding auto-configuration class that relates to a TemplateAvailabilityProvider causes property binding to fail for native images #35682

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

Closed
mmoayyed opened this issue May 31, 2023 · 2 comments
Assignees
Labels
theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Milestone

Comments

@mmoayyed
Copy link
Contributor

mmoayyed commented May 31, 2023

Environment

  • Spring Boot 3.1.0
  • JDK 17
  • GraalVM 22.3.1
  • Gradle 8.1.1
  • Gradle GraalVM native image plugin 0.9.22
  • Groovy 4.0.12

Problem

Excluding an auto-configuration class, such as GroovyTemplateAutoConfiguration via application properties, causes property binding to fail when building and launching GraalVM native images. The basic setup should be as follows (I can certainly put together a reproducer, if it helps to clarify the scenario):

  • In application.yml file, define:
spring:
  autoconfigure:
    exclude: org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration
  • Ensure the application contains the dependency groovy-templates-4.0.12.jar to satisfy the conditions required by GroovyTemplateAutoConfiguration, and then:
./gradlew nativeCompile

Launch the native image to see:

2023-05-31 08:04:47 WARN  o.s.b.w.s.c.ServletWebServerApplicationContext - 
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'welcomePageHandlerMapping': Instantiation of supplied bean failed
2023-05-31 08:04:47 ERROR o.s.b.d.LoggingFailureAnalysisReporter -

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

Description:

Failed to bind properties under 'spring.groovy.template' to 
org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider$GroovyTemplateAvailabilityProperties:

    Reason: java.lang.NoSuchMethodException: 
org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider$GroovyTemplateAvailabilityProperties.<init>()

Action:

Update your application's configuration

Analysis

  • GroovyTemplateAutoConfiguration is tagged with @ImportRuntimeHints({GroovyTemplateRuntimeHints.class}). Excluding the class will also deactivate the runtime hint registration process.

  • This is a bit of a tricky scenario where in the general sense, the app wants to use and have access to the functionality offered by a dependency, i.e. groovy-templates-4.0.12.jar, and yet does not need or want to activate the Spring Boot auto-configuration that detects that library.

  • The following construct does not exclude the auto-configuration class, when attached to the application's entrypoint:

@SpringBootApplication(exclude = {
    GroovyTemplateAutoConfiguration.class
}, proxyBeanMethods = false)

After including the above, the AOT generated sources continue to include bean definitions found and processed by GroovyTemplateAutoConfiguration.

  • Removing the exclusion rules altogether and starting clean with just the noted dependency causes other issues when building and launching GraalVM native images, i.e.:
Error creating bean with name 'groovyMarkupConfigurer': No signature of method: org.codehaus.groovy.control.customizers.ASTTransformationCustomizer$_setAnnotationParameters_closure1.doCall() is applicable for argument types: (SimpleImmutableEntry) values: [extensions=groovy.text.markup.MarkupTemplateTypeCheckingExtension]
Possible solutions: findAll(), findAll(), isCase(java.lang.Object), isCase(java.lang.Object)

...and many other similar errors, all groovy-related. There is no other way to skip the generation of the groovyMarkupConfigurer bean, other than to perhaps reconstruct it again, mute it and allow spring-bean-overriding.

If you'd like to see a reproducer, please let me know.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 31, 2023
@wilkinsona
Copy link
Member

Thanks for the report, @mmoayyed. We don't support Groovy in native images at the moment but there are some more general problems here that we may want to address.

The TemplateAvailabilityProvider implementations are loaded via spring.factories and called through the error infrastructure. This happens irrespective of whether the view technology's auto-configuration was used. If the auto-configuration has been excluded, this also removes the import of the runtime hints that are necessary for the template availability provider to work in a native image.

It looks like we need to decouple the import of the runtime hints from the auto-configurations. Do you have any spring.groovy.template.* properties? I am wondering if such properties are necessary to trigger the problem.

@SpringBootApplication(exclude = { GroovyTemplateAutoConfiguration.class }, proxyBeanMethods = false)

If this doesn't exclude GroovyTemplateAutoConfiguration you have found a bug.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label May 31, 2023
@mmoayyed
Copy link
Contributor Author

Thank you Andy! I appreciate the reference to the docs and the known limitations. (On a related Groovy note and perhaps for future passer-bys, anybody running Spring Boot and native-images with the thymeleaf-layout-dialect, a codebase written in Groovy, will run into similar and much more severe issues)

After a bit of trial and error, research and beating a bunch of other stuff into submission, I was able to get this working:

@SpringBootApplication(exclude = { GroovyTemplateAutoConfiguration.class }, proxyBeanMethods = false)

So no bug there. Apologies for the false alarm. I did also look around and the only setting I could find was spring.groovy.template.enabled=false. I can try to remove this and run the build again, if it helps with diagnostics.

Certainly, I would agree that decoupling the runtime hint registration from the auto-configurations would be best to avoid side-effects such as this.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels May 31, 2023
@philwebb philwebb added the for: team-meeting An issue we'd like to discuss as a team to make progress label May 31, 2023
@philwebb philwebb added type: bug A general bug theme: aot An issue related to Ahead-of-time processing and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided for: team-meeting An issue we'd like to discuss as a team to make progress labels Jun 14, 2023
@philwebb philwebb added this to the 3.0.x milestone Jun 14, 2023
@wilkinsona wilkinsona changed the title Excluding auto-configuration class causes property binding to fail for native images Excluding auto-configuration class the relates to a TemplateAvailabilityProvider causes property binding to fail for native images Jun 23, 2023
@wilkinsona wilkinsona changed the title Excluding auto-configuration class the relates to a TemplateAvailabilityProvider causes property binding to fail for native images Excluding auto-configuration class that relates to a TemplateAvailabilityProvider causes property binding to fail for native images Jun 23, 2023
@wilkinsona wilkinsona self-assigned this Jun 29, 2023
@wilkinsona wilkinsona modified the milestones: 3.0.x, 3.0.9 Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants