spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

CGLIB proxies are not used at runtime on `@Configuration` classes in AOT mode

Open sdeleuze opened this issue 3 years ago • 2 comments

Consider the following configuration class:

@Configuration
public class MyConfiguration {
	@Bean
	A a() { return new A(); }

	@Bean
	B b() { return new B(this.a()); }
	
	static class A {
		public A() { System.out.println("A constructor"); }
	}

	static class B {
		public B(A a) { System.out.println("B constructor"); }
	}
}

On JVM in regular mode, it prints:

A constructor
B constructor

On JVM in AOT mode or native, while it seems CGLIB proxies are generated correctly at build time, but they seems not used since it prints:

A constructor
A constructor
B constructor

The code generated AOT maybe needs to be updated to leverage those CGLIB proxies.

sdeleuze avatar Sep 08 '22 09:09 sdeleuze

We need to swap the creation of the raw class to the cglib proxy. I was hoping I could avoid having to change code generation for this but it turns out that there isn't a way to achieve this using an instance supplier.

I've a proposal in 3b8bcdf.

This is blocked by https://github.com/spring-projects/spring-boot/issues/32304 and, to some extent, https://github.com/spring-projects/spring-framework/issues/29141

snicoll avatar Sep 13 '22 11:09 snicoll

I have it working but I think it needs a bit more work to test it correctly.

snicoll avatar Sep 14 '22 16:09 snicoll