Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

Spring's classpath scanning made it easy to add beans, but in large codebases it also makes it hard to know what is in the context. What container standards would you set for a large organisation's Spring services over the next decade?

I would set a few clear standards: each application scans only its own packages, and libraries contribute beans only through auto-configuration; infrastructure beans are declared explicitly with @Bean or @Import so they can be reviewed; startup time and bean count are tracked metrics; services are written to stay AOT-compatible, with no runtime tricks such as registering beans from network calls; and the standard itself is revisited with each major Spring release. The goal is that anyone can answer what is in the context and why.

Background to this question

In a codebase with hundreds of services, the container is shared infrastructure even when every team writes its own code. Component scanning lets any developer add a bean by adding an annotation, which is wonderful for productivity and terrible for knowing what is running. Over a decade, that leads to slow startups, surprise beans from libraries and services that cannot move to AOT or native images. A leadership question like this wants standards with reasons, a way to enforce them without slowing teams down, and a plan for keeping them current. In this answer, we will look at the problem in concrete terms, go through each standard with its reasoning, cover how to measure and enforce them, and end with how the standard evolves.

1A Quick Recap of the Problem

Spring Boot builds the application context from three sources: component scanning of the application's packages, auto-configurations from the libraries on the classpath, and any configuration imported explicitly. Scanning registers every class with a stereotype annotation; auto-configurations contribute beans based on conditions such as classes present and properties set.

In a small service this is easy to reason about. In a large organisation, a typical service may have 600 to 1,500 beans, of which the team wrote perhaps a tenth. When something odd happens, such as an unexpected scheduler, a second ObjectMapper or a filter that changes every response, the first question is where the bean came from, and with broad scanning of shared package prefixes the answer can take hours to find.

2Standard 1: Applications Scan Only Their Own Code

Each service's main class lives in the service's own root package, for example com.acme.orders, and scanning stays there. No service scans com.acme, the shared prefix, because that reaches into every library using the same prefix. Libraries never use @ComponentScan on themselves and never rely on being scanned; they contribute beans through auto-configuration with @ConditionalOnMissingBean and documented properties, so a service can override or disable them.

The reasoning is ownership. A team should own exactly what is in its packages, and a library owner should own the defaults the library provides, through a small set of switches. With this rule, the answer to where a bean came from is always either our package or a named auto-configuration, and the conditions report tells us which.

3Standard 2: Explicit Configuration for Infrastructure

For business components such as controllers, services and repositories, scanning is fine: they are many, they are simple and the package structure documents them. For infrastructure, meaning data sources, HTTP clients, security filter chains, message listener containers, thread pools and serializers, we declare beans with @Bean methods in configuration classes, or import them explicitly. These beans change behaviour for the whole service and deserve code review like any other important decision.

A @Bean method also shows the configuration values in one place: the pool size, the timeouts, the retry policy. That makes reviews and incident analysis faster, because the question how is this client configured has one answer in one file.

Java
@Configuration(proxyBeanMethods = false)
class OutboundClientsConfig {
@Bean
RestClient pricingClient(RestClient.Builder builder, PricingProperties p) {
return builder.baseUrl(p.baseUrl().toString())
.requestFactory(ClientHttpRequestFactoryBuilder.jdk()
.build(ClientHttpRequestFactorySettings.defaults()
.withConnectTimeout(Duration.ofSeconds(1))
.withReadTimeout(p.timeout()))) // visible, reviewed values
.build();
}
}

The exact builder methods for request factory settings have changed across Spring Boot 3.x releases, so check your version; the point is that the values sit in reviewed code, not in a scanned class nobody looks at.

4Standard 3: Measure Startup Time and Bean Count

What is not measured drifts. Every service reports two numbers at each deployment: time from process start to ready, and the number of beans in the context. Both are easy to obtain, from ApplicationReadyEvent timing or the startup endpoint and from the bean factory's definition count, and both go to a fleet dashboard.

Neither number has a universal right value, but changes are informative. A service whose bean count jumps from 800 to 1,100 after a library upgrade has picked up something new, and a service whose startup grows from 8 to 30 seconds over a year needs attention before it hurts deployments. Teams can set their own budgets; the platform team watches the trends and the outliers.

Container standards and how we check them
StandardReasonEnforcement
Scan only own packagesclear ownership of beansArchUnit rule, build check of scan roots
Libraries use auto-configurationconsumers control defaultslibrary review checklist, starter template
Infrastructure via @Bean or @Importreviewable configurationcode review, architecture tests
Track startup time and bean countcatch drift earlydeployment metrics, dashboard
Stay AOT-compatiblekeep native and fast-start options openAOT build in CI for key services
Revisit each major releasestandards follow the platformyearly review, written decision log

5Standard 4: Design for AOT Compatibility

Spring AOT and native images evaluate the bean graph at build time. Services that decide which beans exist from data fetched at runtime, such as registering one bean per entry from a configuration service call, register beans from a database, build heavy reflection by hand, or create proxies themselves, cannot move to AOT later without rework. Even services that will never be native images benefit from AOT-friendly design, because it is also the design that is easiest to read: the beans are knowable from the code and the configuration.

So the standard forbids those runtime tricks in services, allows dynamic registration only in reviewed platform libraries that support AOT, and runs an AOT build in CI for a few representative services so we learn early when something breaks it. Startup-sensitive workloads can then opt into AOT or native images without first untangling their configuration.

6Standard 5: Revisit the Standard With Each Major Release

A ten-year standard cannot be written once. Spring Boot 2 to 3 changed the auto-configuration registration file and moved to Jakarta; Spring Framework 7 adds programmatic bean registration with BeanRegistrar; JDK features such as class data sharing and the AOT cache change the startup picture. So the standard has an owner, a short written document with the reason for every rule, and a review with each major Spring release, where we add, change or drop rules.

We roll changes out the way we roll out libraries: the internal starter and the service template embody the current standard, so most teams follow it by upgrading a dependency rather than reading a document. Exceptions are allowed with a written reason, and repeated exceptions are a signal that the rule should change.

Step throughKeeping the standard current
  1. New major Spring or JDK releaseread the release notes
  2. Does a rule block a useful new feature?
    YesChange or drop the ruleNoGo on
  3. Are teams filing repeated exceptions?
    YesRevisit that ruleNoKeep it
  4. Update the starter and service templateteams adopt by upgrading

4 steps in order. Play them, or step through them one at a time.

7Follow-up questions

Isn't banning broad scanning too strict for small teams?

The rule is only about scanning shared prefixes and libraries scanning themselves. Within its own package, a team can scan as much as it likes. The cost is low, putting the main class in the service's root package, and the benefit, knowing where every bean comes from, grows with the size of the organisation.

How do you enforce rules about scanning automatically?

ArchUnit tests in the service template can check that the main class sits in the service's root package and that no class outside the service's packages carries a stereotype annotation. For libraries, a test can assert that no @ComponentScan is present and that the auto-configuration imports file exists. These run in normal CI, so the feedback is immediate.

What would make you relax the AOT rule?

If the organisation has no startup-sensitive workloads and no plans for native images, and a team needs dynamic registration for a strong reason, I would allow it in that service with a written decision. The rule exists to keep options open; when the option has no value for a service, the rule should not block a good design.

8Conclusion

In this answer, we set container standards for a large organisation: scan only the application's own packages and let libraries contribute through auto-configuration, declare infrastructure explicitly with @Bean or @Import so it can be reviewed, track startup time and bean count as metrics, design for AOT compatibility by avoiding runtime tricks such as registering beans from network calls, and revisit the standard with each major Spring release. We enforce them through the service template, internal starters, architecture tests and dashboards, so following them is the easy path.

What to say in the interviewAbout 90 seconds aloud

Open with

My aim is that anyone in the organisation can answer what is in a service's context and why. So the first standard is about scanning: each service scans only its own root package, never a shared prefix like com.acme, and libraries never scan themselves.

Then, if they want more

They contribute beans through auto-configuration with @ConditionalOnMissingBean and documented properties, so services can override or disable them. Second, business components can be scanned, but infrastructure, data sources, HTTP clients, security chains, thread pools, serializers, is declared with explicit @Bean methods or imports, because those beans affect the whole service and their settings should be visible in code review.

Third, every service reports its startup time and bean count at each deployment to a dashboard, because those numbers tell us early when a library upgrade drags in hundreds of beans or startup slowly creeps from eight to thirty seconds.

Fourth, we design for AOT compatibility: no registering beans from network calls or databases, no hand-built proxies or reflection in services, and an AOT build in CI for a few representative services, so fast-start and native options stay open. And finally, the standard has an owner and is reviewed at each major Spring release.

I would embed it in the service template and the internal starter, with ArchUnit checks, so teams follow it by upgrading a dependency rather than by reading a wiki page.

About this answer

Last updated
12 November 2026
Versions it names
Spring Boot 2, Spring Boot 3, Spring Framework 7
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 "Spring's classpath scanning made it easy to add beans, but in large codebases it also...": https://scrivio-interview-library.netlify.app/spring-boot/ioc-container/d8a4e1ed91/