Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

Spring has dominated Java dependency injection for two decades, while frameworks such as Micronaut, Quarkus and Dagger do more of the injection work at build time. How do you frame the long-term bet on DI for your platform?

I would frame it as two separate bets. The framework bet stays with Spring for an existing platform, because Spring's AOT processing in Framework 6 narrowed the startup gap with build-time frameworks, and switching hundreds of services would cost far more than it saves, while ecosystem, hiring and support favour Spring. The code bet is what protects us: constructor-injected business code with few framework annotations is portable between containers, so a future move, or a few services on Quarkus, Micronaut or Dagger where startup really matters, stays possible.

Why this question is asked

A DI framework is one of the longest-lived choices on a Java platform: it touches every class, every test and every engineer's habits. Startup time and memory now matter more than they did, because of autoscaling, serverless functions and native images, and frameworks that do injection at build time advertise large gains. Interviewers ask this at the most senior level to see whether we can separate a real technical shift from a fashion, and turn it into a decision that still looks right in ten years. In this answer, we will recap run-time and build-time injection, see what run-time reflection costs, look at how Spring responded, weigh the cost of switching, and then set the guidelines that keep our options open.

1A Quick Recap: Run-Time and Build-Time Injection

Classic Spring does injection at run time. When the application starts, it scans the classpath for annotated classes, reads their annotations and constructor parameters through reflection, builds bean definitions, creates proxies for transactions and other features, and only then creates the beans. All of this happens in every start of every instance.

Build-time frameworks move that work into compilation. Dagger generates plain Java factory code from annotations with an annotation processor, so at run time there is no scanning and no reflection at all. Micronaut also processes annotations at compile time. Quarkus does most of its CDI-based wiring during the build and records the result. At run time they mostly execute generated code.

Where the wiring work happens
Framework styleDiscovery and wiringRun-time reflectionTypical strength
Spring, classic JVM modeAt every startupYes, a lotEcosystem, flexibility
Spring with AOTMostly at build timeMuch lessFaster start, native image support
QuarkusAt build timeLittleFast start, native images
MicronautAt compile timeLittleFast start, low memory
DaggerGenerated code at compile timeNoneSmallest runtime, Android

2What Run-Time Reflection Costs

Reflection-based startup costs time and memory. A medium Spring Boot service may take several seconds to start on the JVM, which matters when we scale out under load, when a serverless function starts cold, or when a deployment restarts 300 instances. Reflection also keeps metadata about many classes in memory.

It also clashes with closed-world compilation. GraalVM native image compiles the application ahead of time under a closed-world assumption: everything that can run must be known at build time. Reflection, dynamic proxies and classpath scanning are exactly the dynamic tricks that break that assumption unless they are described in metadata. A framework that discovers beans at run time cannot be compiled this way without help.

3How Spring Narrowed the Gap

Spring Framework 6 and Spring Boot 3 added AOT processing. During the build, Spring runs the bean discovery once, then generates Java code that registers the bean definitions directly, plus the reflection and proxy metadata native image needs. At run time, the application uses that generated code instead of scanning. This supports GraalVM native images and also speeds up normal JVM starts. The JDK itself is moving in the same direction: Project Leyden's ahead-of-time cache, which started arriving in JDK 24, stores class loading and linking work from a training run, and Spring Boot supports class data sharing; check your versions for the details.

There is a trade-off: AOT mode fixes some decisions at build time, so conditions that depend on the run-time environment, such as which profile is active, must be decided earlier. But the important point for the long-term bet is that the gap is now a matter of degree, not of kind.

4The Real Cost of Switching

Here is the reasoning a senior person uses. Suppose the platform has 400 Spring services. Moving them to another DI framework means rewriting configuration, replacing Spring-specific features such as Spring Data repositories, Spring Security and Spring's transaction support with equivalents, retraining hundreds of engineers, rebuilding shared libraries and auto-configurations, and running two stacks in production for years. Even at a modest two engineer-weeks per service, that is around 800 engineer-weeks, while the main benefit, faster startup, matters for only some of those services.

Non-technical factors weigh as much. Spring has the largest ecosystem, the largest hiring pool, long-standing commercial support and many years of documentation and answers. Those reduce cost every day. So for an existing platform, the bet is to stay with Spring, adopt AOT and the JDK's startup features where startup matters, and allow a different framework for specific workloads, for example short-lived functions, when a team shows the numbers.

5Keeping the Code Portable

The second bet is about our own code, and it is cheap and lasting. Business code written with constructor injection and few framework annotations moves between containers with little change, because every container understands constructors.

Java
// Portable: plain constructor, no framework types in the domain class
public final class PricingService {
private final RateRepository rates;
private final Clock clock;
public PricingService(RateRepository rates, Clock clock) { this.rates = rates; this.clock = clock; }
}
// Framework-specific wiring stays at the edge, in one small class per framework
@Configuration
class PricingConfig {
@Bean PricingService pricingService(RateRepository rates, Clock clock) {
return new PricingService(rates, clock);
}
}
// moving to Quarkus or Dagger means rewriting PricingConfig, not PricingService

Notice that PricingService has no Spring import. The @Configuration class is the composition root for Spring; a Dagger module or a CDI producer would do the same job for another framework. The guideline for teams is that domain and service classes use constructor injection and avoid framework annotations where a configuration class can do the wiring, while framework features such as transactions and web endpoints stay in clearly separated layers.

6Framing It for the Organisation

We would write the decision down as an architecture decision record: Spring remains the standard; AOT and JDK startup features are adopted where startup or memory is measured to matter; other frameworks are allowed for named workload types with an owner; and all business code follows the portability guidelines. We would revisit it every two years with fresh measurements, because the right answer depends on numbers that keep changing.

7Follow-up questions

Would you choose differently for a new platform starting today?

Possibly. If the workload is dominated by short-lived functions or very dense deployments, a build-time framework could be the better default, and Spring's AOT mode is also a strong option. I would prototype two or three representative services and compare startup, memory, developer productivity and library support before deciding.

Does AOT make Spring as fast as Quarkus or Micronaut?

It narrows the gap considerably, especially in native images, but results depend on the application and versions, so I would measure rather than assume. For most long-running services, the difference after AOT is small compared with other costs.

What is the risk of the portability guideline?

Taken too far, it leads to wrapping every framework feature in our own abstraction, which adds code without value. The guideline is narrower: keep business classes on plain constructors and let the framework handle infrastructure at the edges.

8Conclusion

In this answer, we framed the long-term DI bet for a platform. Run-time reflection-based injection costs startup time and complicates closed-world AOT compilation, which build-time frameworks avoid. Spring responded with AOT processing in Framework 6, narrowing the gap. Switching hundreds of services is very costly, and ecosystem, hiring and support often matter more than startup. So we stay with Spring where it serves us and keep business code on constructor injection with few framework annotations, which keeps a future move possible.

What to say in the interviewAbout 80 seconds aloud

Open with

I would split it into a framework bet and a code bet. On the framework, run-time reflection-based injection does cost startup time and memory, and it fights closed-world compilation like GraalVM native image, which is why Dagger, Micronaut and Quarkus move the wiring to build time.

Then, if they want more

But Spring responded with AOT processing in Framework 6 and Boot 3, which generates the bean registration code at build time and supports native images, so the gap is now a matter of degree.

For an existing platform of hundreds of Spring services, switching would cost many hundreds of engineer-weeks, plus retraining and running two stacks, and Spring's ecosystem, hiring pool and support save us money every day.

So I'd stay with Spring, use AOT and the JDK's startup features where measurements show startup matters, and allow a build-time framework for specific workloads like short-lived functions when a team brings the numbers.

The code bet is what really protects us: business classes use constructor injection and avoid framework annotations, with the wiring in small configuration classes at the edge. Then moving any service later means rewriting its configuration, not its logic. I'd record this in an architecture decision record and revisit it with fresh measurements every couple of years.

About this answer

Last updated
12 November 2026
Versions it names
Java 24, Spring Boot 3, 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 official documentation for the version you use. 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 "Spring has dominated Java dependency injection for two decades, while frameworks such as...": https://scrivio-interview-library.netlify.app/java/creational-patterns/491ff8e01f/