Description

When running a container image that has been build with spring-boot:build-image and <BP_JVM_JLINK_ENABLED>true</BP_JVM_JLINK_ENABLED>, using a Repository class that utilizes constructor autowiring will throw an AopConfigurationException.

The stacktrace indicates that the CGLib transformed constructor is not availabile at runtime.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ooo.sansk.demo.buildpacks.BuildpacksApplication$BasicRepository': Unexpected AOP exception
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:607) ~[spring-beans-6.1.13.jar:6.1.13]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) ~[spring-beans-6.1.13.jar:6.1.13]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337) ~[spring-beans-6.1.13.jar:6.1.13]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.13.jar:6.1.13]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335) ~[spring-beans-6.1.13.jar:6.1.13]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.1.13.jar:6.1.13]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975) ~[spring-beans-6.1.13.jar:6.1.13]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:971) ~[spring-context-6.1.13.jar:6.1.13]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:625) ~[spring-context-6.1.13.jar:6.1.13]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-3.3.4.jar:3.3.4]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) ~[spring-boot-3.3.4.jar:3.3.4]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) ~[spring-boot-3.3.4.jar:3.3.4]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) ~[spring-boot-3.3.4.jar:3.3.4]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) ~[spring-boot-3.3.4.jar:3.3.4]
        at ooo.sansk.demo.buildpacks.BuildpacksApplication.main(BuildpacksApplication.java:13) ~[classes/:0.0.1-SNAPSHOT]
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Unknown Source) ~[na:na]
        at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:102) ~[workspace/:na]
        at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:64) ~[workspace/:na]
        at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:40) ~[workspace/:na]
Caused by: org.springframework.aop.framework.AopConfigException: Unexpected AOP exception
        at org.springframework.aop.framework.CglibAopProxy.buildProxy(CglibAopProxy.java:236) ~[spring-aop-6.1.13.jar:6.1.13]
        at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:163) ~[spring-aop-6.1.13.jar:6.1.13]
        at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110) ~[spring-aop-6.1.13.jar:6.1.13]
        at org.springframework.aop.framework.AbstractAdvisingBeanPostProcessor.postProcessAfterInitialization(AbstractAdvisingBeanPostProcessor.java:127) ~[spring-aop-6.1.13.jar:6.1.13]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:438) ~[spring-beans-6.1.13.jar:6.1.13]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1809) ~[spring-beans-6.1.13.jar:6.1.13]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:600) ~[spring-beans-6.1.13.jar:6.1.13]
        ... 19 common frames omitted
Caused by: org.springframework.aop.framework.AopConfigException: Unable to instantiate proxy using Objenesis, and regular proxy instantiation via default constructor fails as well
        at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:86) ~[spring-aop-6.1.13.jar:6.1.13]
        at org.springframework.aop.framework.CglibAopProxy.buildProxy(CglibAopProxy.java:221) ~[spring-aop-6.1.13.jar:6.1.13]
        ... 25 common frames omitted
Caused by: java.lang.NoSuchMethodException: ooo.sansk.demo.buildpacks.BuildpacksApplication$BasicRepository$$SpringCGLIB$$0.<init>()
        at java.base/java.lang.Class.getConstructor0(Unknown Source) ~[na:na]
        at java.base/java.lang.Class.getDeclaredConstructor(Unknown Source) ~[na:na]
        at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:80) ~[spring-aop-6.1.13.jar:6.1.13]
        ... 26 common frames omitted

Reproduction

  1. Clone the repository from https://github.com/SanderKnauff/buildpack-aop-jlink-broken
  2. Run ./mvnw -DskipTests package spring-boot:process-aot spring-boot:build-image
  3. Then run the created image using docker run buildpacks:0.0.1-SNAPSHOT.

Note

The repository contains configuration for Podman, I have not tested this against docker, but I expect the results to be the same. The podman configuration will only activate when -Ppodman is added to the mvn command.

Comment From: wilkinsona

Thanks for the report. Given that the problem only occurs with <BP_JVM_JLINK_ENABLED>true</BP_JVM_JLINK_ENABLED>, I think this should be investigated by the buildpacks team in the first instance at least. I think that https://github.com/paketo-buildpacks/libjvm is the repository where that functionality is maintained. Please open an issue over there and comment here with a link to it so that we can follow along.

Comment From: SanderKnauff

Thanks for the report. Given that the problem only occurs with <BP_JVM_JLINK_ENABLED>true</BP_JVM_JLINK_ENABLED>, I think this should be investigated by the buildpacks team in the first instance at least. I think that https://github.com/paketo-buildpacks/libjvm is the repository where that functionality is maintained. Please open an issue over there and comment here with a link to it so that we can follow along.

Thank you. I have reported this issue in their repository. It can be found here: https://github.com/paketo-buildpacks/libjvm/issues/432