Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

Proxies and aspects underpin many Spring features. Considering AOT compilation and native images, how do you see the long-term role of runtime proxies in Java frameworks?

Runtime proxies depend on generating classes and using reflection while the application runs, which conflicts with the closed world of a native image. Spring keeps its proxy-based features working there by generating the proxy classes and reflection hints at build time with Spring AOT, while frameworks such as Quarkus and Micronaut generate the interception code at build time and avoid runtime proxies altogether. I expect annotation-driven cross-cutting features to stay, with their implementation moving into the build, so teams should not rely on proxy internals such as generated class names or object identity.

Background to this question

A large part of Spring is built on proxies: transactions, caching, security, async methods, scoped beans and configuration classes all work because Spring wraps our objects at startup. Native images and ahead-of-time compilation change the economics of that design, and a senior engineer is expected to have a view on where it is going, because it affects which frameworks we choose, how we write code and how much a migration will cost. In this answer, we will recap what a runtime proxy is, see why it conflicts with native images, look at how Spring AOT and build-time frameworks respond, and finish with what this means for our own code and decisions.

1A Quick Recap of Runtime Proxies

A proxy is an object that stands in for another and intercepts calls to it. Spring creates two kinds at startup. A JDK dynamic proxy implements the bean's interfaces and forwards each call to an invocation handler; the JDK generates its class at run time with java.lang.reflect.Proxy. A CGLIB proxy, which Spring uses by default in Spring Boot, is a generated subclass of the bean's class that overrides its methods. Either way, the proxy runs the interceptor chain, for example starting a transaction, and then calls the real method, often reflectively.

The important part for this discussion is when the work happens: the proxy class does not exist in our compiled code. Spring decides at startup which beans need proxies, generates their bytecode, defines the classes in a class loader, and calls methods through reflection. That flexibility is why Spring can add behaviour to almost any bean, and also why it costs startup time and memory.

2Why Proxies Conflict With Native Images

A GraalVM native image is compiled ahead of time into a single executable. To do that, the compiler performs a closed-world analysis: it must see every class, method and reflective access that could ever be used, and anything it does not see is left out. At run time there is no way to define a new class from bytecode, and reflection only works for elements that were registered at build time.

So the two pillars of runtime proxies, generating classes on the fly and calling methods reflectively, both need help. JDK proxies must be declared at build time so the image builder can generate them in advance. CGLIB subclasses cannot be generated at run time at all. Without build-time preparation, a Spring application that relies on proxies would fail in a native image with errors about missing classes or reflection configuration.

Where the proxy work happens
ApproachProxy classes createdFits native images?
Classic Spring on the JVMAt startup, by CGLIB or the JDKNo, needs class generation at run time
Spring AOTAt build time, same proxy designYes, with generated classes and hints
Build-time frameworks (Quarkus, Micronaut)At build time, as interceptor codeYes, no runtime proxies needed
The feature stays the same; the moment the code is generated moves earlier.

3How Spring AOT Keeps Proxies Working

Spring Framework 6 introduced an ahead-of-time engine, usually called Spring AOT, that runs during the build. It starts the application context far enough to know which beans exist and which need proxies, then writes the result out as generated source and classes: bean definitions as plain Java code, CGLIB proxy classes for configuration classes and other proxied beans, and runtime hints that list the reflection, resources and JDK proxies the image builder must include. The Spring Boot build plugins run it when we build a native image or enable AOT processing on the JVM.

The price of this approach is a fixed world. Conditions are evaluated at build time, so a bean that depends on a property set only at run time behaves differently from the JVM, and profiles that change the bean graph must be chosen at build time. Libraries that create proxies or use reflection in ways Spring cannot see must contribute their own hints, which is why some older libraries need extra configuration or do not work in native images yet.

Java
// A library or application can register what its own code needs at run time
class AuditHints implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
hints.proxies().registerJdkProxy(AuditSink.class); // JDK proxy created later
hints.reflection().registerType(AuditRecord.class, MemberCategory.INVOKE_PUBLIC_METHODS);
}
}
@Configuration
@ImportRuntimeHints(AuditHints.class)
class AuditConfig { }

4The Build-Time Alternative

Other frameworks chose a different design from the start. Micronaut uses annotation processing during compilation to generate the dependency injection and interception code, and Quarkus does most of its work in a build step that generates interceptor subclasses and wiring ahead of time. In both, @Transactional or a custom interceptor binding still works through an annotation, but the code that runs is ordinary compiled code written by the build, not a proxy generated by a library at startup.

The result is fast startup and good native image support without hints for the framework's own features. The trade-off is less dynamism: the bean graph is fixed at build time, and some patterns that rely on runtime decisions are harder or impossible. The JVM itself is also moving in this direction with ahead-of-time cache work in recent JDK releases, which stores the results of class loading and linking from a training run; it speeds up startup but does not remove the need to reason about what is known at build time.

5What This Means for Our Code and Decisions

My view is that annotation-driven cross-cutting features will remain the way Java developers work. @Transactional, @Cacheable or an observation annotation express intent clearly, and every major framework supports them. What changes is the implementation: more of it moves into the build, and the gap between how Spring and the build-time frameworks work will keep narrowing.

For teams, the practical rule is to depend on the behaviour, not on the mechanism. Code that checks whether a class name contains $$SpringCGLIB$$, compares beans with == against unwrapped targets, calls getClass() to find annotations instead of using AopUtils or the annotation utilities, or relies on proxies being created for beans that are decided only at run time will break when the implementation changes. Code that simply uses the annotations and lets the framework apply them will not.

When we choose frameworks for new services, the relevant question is less 'proxies or not' and more how much we need native images or very fast startup. For a long-running service on the JVM, classic Spring proxies cost a little startup time and nothing else. For functions that scale to zero or command-line tools, Spring AOT or a build-time framework is worth the extra constraints.

6Follow-up questions

Does Spring AOT change how my application behaves on the JVM?

Only when we turn it on for the JVM, and then mostly in startup speed. The behaviour that changes is anything decided at build time: conditions, profiles that alter the bean graph and properties read during bean definition. The Spring Boot documentation lists these constraints, and it is worth testing the AOT-processed application the same way we test the normal one.

Will runtime proxies disappear from Spring?

I do not expect that soon. Many applications run on the JVM where proxies work well, and Spring AOT shows that the same proxy design can be prepared at build time when needed. What I expect is that more of the proxy work moves into the build by default, and that APIs which expose proxy details become less important.

7Conclusion

In this answer, we saw that runtime proxies rely on generating classes and using reflection while the application runs, which conflicts with the closed-world analysis of native images. Spring AOT answers this by generating the proxy classes, bean definitions and runtime hints during the build, while Quarkus and Micronaut generate interception code at build time and need no runtime proxies. Annotation-driven cross-cutting features will stay, their implementation is moving into the build, and our code should rely on what the annotations promise rather than on proxy class names or identity.

What to say in the interviewAbout 90 seconds aloud

Open with

Runtime proxies are how Spring adds transactions, caching, security and async to beans: at startup it generates a CGLIB subclass or a JDK proxy and calls through reflection.

Then, if they want more

That is flexible, but it conflicts with GraalVM native images, which are compiled under a closed-world assumption and cannot define new classes at run time or reflect on anything not registered at build time.

Spring's answer since Framework 6 is Spring AOT: during the build it works out the bean graph, generates the proxy classes and bean definitions as code, and records runtime hints for reflection and JDK proxies. Quarkus and Micronaut took the other path and generate interception code at build time, so there are no runtime proxies at all.

My view is that annotation-driven cross-cutting features will stay, because they express intent well, but the implementation keeps moving into the build. So for teams I would set two rules. Depend on behaviour, never on proxy internals: no checks on CGLIB class names, no identity comparisons between proxies and targets, use AopUtils and annotation utilities.

And know the build-time constraints, such as conditions and profiles evaluated at build time, before adopting native images. For long-running JVM services I would happily keep classic proxies; for scale-to-zero or CLI workloads I would invest in AOT or a build-time framework.

About this answer

Last updated
12 November 2026
Versions it names
Spring Framework 6
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Proxies and aspects underpin many Spring features. Considering AOT compilation and...": https://scrivio-interview-library.netlify.app/spring-boot/aop/872f30e5b0/