Skip to content
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

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

Closed
sdeleuze opened this issue Sep 8, 2022 · 2 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Milestone

Comments

@sdeleuze
Copy link
Contributor

sdeleuze commented Sep 8, 2022

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 sdeleuze added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing labels Sep 8, 2022
@sdeleuze sdeleuze added this to the 6.0.0-M6 milestone Sep 8, 2022
@sdeleuze sdeleuze changed the title CGLIB proxies are not used at runtime on @Configuration in AOT mode CGLIB proxies are not used at runtime on @Configuration classesin AOT mode Sep 8, 2022
@sdeleuze sdeleuze changed the title CGLIB proxies are not used at runtime on @Configuration classesin AOT mode CGLIB proxies are not used at runtime on @Configuration classes in AOT mode Sep 8, 2022
snicoll added a commit to snicoll/spring-framework that referenced this issue Sep 13, 2022
@snicoll
Copy link
Member

snicoll commented Sep 13, 2022

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 spring-projects/spring-boot#32304 and, to some extent, #29141

snicoll added a commit to snicoll/spring-framework that referenced this issue Sep 13, 2022
snicoll added a commit to snicoll/spring-framework that referenced this issue Sep 13, 2022
This commit updates code generation to customize the instantiation of
a configuration class that requires a proxy. Rather than instantiating
the raw class, the proxy is used.

See spring-projectsgh-29107
@snicoll snicoll modified the milestones: 6.0.0-M6, 6.0.0-RC1 Sep 14, 2022
@snicoll
Copy link
Member

snicoll commented Sep 14, 2022

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

snicoll added a commit to snicoll/spring-framework that referenced this issue Sep 15, 2022
This commit updates code generation to customize the instantiation of
a configuration class that requires a proxy. Rather than instantiating
the raw class, the proxy is used.

See spring-projectsgh-29107
snicoll added a commit to snicoll/spring-framework that referenced this issue Sep 15, 2022
This commit updates code generation to customize the instantiation of
a configuration class that requires a proxy. Rather than instantiating
the raw class, the proxy is used.

See spring-projectsgh-29107
snicoll added a commit to snicoll/spring-framework that referenced this issue Sep 15, 2022
This commit updates code generation to customize the instantiation of
a configuration class that requires a proxy. Rather than instantiating
the raw class, the proxy is used.

See spring-projectsgh-29107
snicoll added a commit to snicoll/spring-framework that referenced this issue Sep 15, 2022
This commit updates code generation to customize the instantiation of
a configuration class that requires a proxy. Rather than instantiating
the raw class, the proxy is used.

See spring-projectsgh-29107
snicoll added a commit to snicoll/spring-framework that referenced this issue Sep 19, 2022
This commit updates code generation to customize the instantiation of
a configuration class that requires a proxy. Rather than instantiating
the raw class, the proxy is used.

See spring-projectsgh-29107
jhoeller added a commit that referenced this issue Oct 3, 2022
…ing)

For non-required method proxies, prefer regular reflective invocation instead.

See gh-29107
jhoeller added a commit that referenced this issue Oct 3, 2022
…ssing)

Method proxies might not actually be used later on, so failure is not fatal.

See gh-29107
jhoeller added a commit that referenced this issue Oct 3, 2022
Do not trigger early initialization on Factory classes (e.g. AOP proxies)

See gh-29107
@jhoeller jhoeller self-assigned this Oct 4, 2022
jhoeller added a commit that referenced this issue Oct 4, 2022
This propagates current Enhancer settings (naming strategy etc) to the method proxies.

See gh-29107
@snicoll snicoll closed this as completed in 2f20d63 Oct 4, 2022
izeye added a commit to izeye/spring-framework that referenced this issue Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants