Scrivio Interview library
ScenarioPrincipal7 min read · updated 12 November 2026

An old in-house framework built on Spring uses dozens of BeanFactoryPostProcessors to rewrite bean definitions at startup. It blocks upgrades and AOT. How would you plan its retirement?

We retire a framework like this the way we would pay off any large debt: first we list what every post-processor actually does and who depends on it, then we replace each behaviour with a standard Spring Boot mechanism such as auto-configuration, conditions, @ConfigurationProperties or a customiser, and we switch the old post-processors off one at a time behind feature switches, with tests proving nothing changed. Meanwhile we freeze new features in the old framework and fix a timeline tied to the support dates of the Spring versions we are leaving.

Why this question is asked

Many companies built an internal framework on Spring ten or fifteen years ago, when Spring Boot did not exist or was young. A common trick in them was a BeanFactoryPostProcessor that rewrites bean definitions at startup, which hides behaviour, relies on internal details, and fights with ahead-of-time (AOT) processing. Interviewers ask this question at senior level to see whether we can run a long migration safely, not just name the replacement APIs. In this answer, we will recap what a BeanFactoryPostProcessor is and why it blocks upgrades and AOT, build an inventory, map each behaviour to a standard mechanism, retire the post-processors one by one, and organise the people and the timeline around it.

1A Quick Recap of BeanFactoryPostProcessor

When a Spring application starts, the container first reads bean definitions: small descriptions of each bean, saying which class to create, which scope it has, which constructor arguments and property values to use. Only later does it create the beans themselves. A BeanFactoryPostProcessor is a hook that runs in between. It receives the bean factory with all the definitions loaded and may change them before a single ordinary bean exists.

This is a powerful position. A post-processor can change the class of a bean, add property values, register extra definitions or remove some. Spring itself uses it, for example to read @Configuration classes. The trouble starts when a framework uses dozens of them to rewrite definitions by its own rules.

Java
public class LegacyDaoRewriter implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory bf) {
for (String name : bf.getBeanDefinitionNames()) {
BeanDefinition bd = bf.getBeanDefinition(name);
if (name.endsWith("Dao")) {
bd.setBeanClassName("com.acme.legacy.AuditingDaoWrapper"); // silently swaps the class
bd.getPropertyValues().add("region", System.getenv("REGION")); // reads the environment at startup
}
}
}
}

Notice two things in this typical example. The class of every bean whose name ends in Dao is swapped by a naming rule that no reader of the DAO would guess. And a value is read from the environment at the moment the definitions are rewritten. Both are the kind of behaviour that breaks during upgrades and AOT.

2Why These Post-Processors Block Upgrades and AOT

Upgrades hurt because rewriting definitions depends on details of the bean definition model, such as which definition classes Spring creates or the order post-processors run in. Spring does not promise these, so they move between major versions.

AOT hurts in a different way. With Spring Framework 6 and later, AOT processing refreshes the application context at build time, runs the bean factory post-processors, and writes the resulting bean definitions out as generated Java code. At runtime, especially in a GraalVM native image, the application uses that generated code instead of analysing the configuration again. So a post-processor that reads the environment, the host name or a remote file at startup has its result frozen at build time. A post-processor that generates classes on the fly or uses hidden reflection breaks the native image.

3Build an Inventory of Behaviour, Not of Classes

Before changing anything, we need to know what each post-processor does and which services rely on it. Reading the code is a start, but we also measure behaviour. A practical trick is a small diagnostic that dumps every bean definition, with its class, scope and property values, once with the legacy post-processors active and once with them disabled. The difference between the two dumps is exactly what the framework changes for that service.

We then record each behaviour in one place: what it does, which services see it (from the dumps across all services, and from a search of the code), whether anything depends on it, and which standard mechanism could replace it. Often a large share of the rewrites turn out to be dead, handling a library nobody uses any more, and those can be removed early.

Inventory: legacy rewrite -> standard replacement
Legacy post-processorWhat it really doesStandard replacement
DaoRewriterWraps every *Dao bean with auditingAn explicit aspect or a decorator bean
RegionInjectorSets region property from env var@ConfigurationProperties record
DataSourceSwapperReplaces DataSource class per profileAuto-configuration with @ConditionalOnProperty
JacksonTweakerEdits ObjectMapper bean definitionA Jackson builder customiser bean
CacheEnablerAdds cache interceptors by naming rule@Cacheable on the methods that need it
OldJmsFixerPatches a library nobody uses nowDelete it
The inventory is about behaviour and who depends on it, not about which class does it.

4Map Each Behaviour to a Standard Mechanism

Almost every rewrite has a supported equivalent today. Values pushed into definitions become @ConfigurationProperties classes, which bind and validate settings at startup. Beans swapped depending on the environment become auto-configuration classes in an internal starter, guarded by conditions such as @ConditionalOnProperty or @ConditionalOnMissingBean, so a service can still define its own bean. Changes to a library bean, such as an ObjectMapper, become customiser beans that Spring Boot calls while it builds that bean. Behaviour added by naming rules becomes an explicit aspect or annotation.

The key property of these mechanisms is that Spring Boot and the AOT engine understand them. If a behaviour truly needs to register bean definitions programmatically, Spring Framework 7 offers the BeanRegistrar interface, a supported and AOT-friendly way to register beans in code (check your version); before that, an ImportBeanDefinitionRegistrar is the less risky choice.

Java
// Before: RegionInjector rewrote property values of 40 bean definitions.
// After: one typed, validated settings class that any bean can take in its constructor.
@ConfigurationProperties(prefix = "acme.region")
@Validated
public record RegionProperties(@NotBlank String name, Duration failoverDelay) {}
@AutoConfiguration
@EnableConfigurationProperties(RegionProperties.class)
public class AcmeRegionAutoConfiguration {
@Bean
@ConditionalOnMissingBean
RegionRouter regionRouter(RegionProperties props) {
return new RegionRouter(props.name(), props.failoverDelay());
}
}

Now the service team can read the configuration, override the bean, and see a startup error if acme.region.name is missing.

5Retire Post-Processors One at a Time

The safest order is to retire one post-processor at a time, starting with dead ones, then those with few dependants, and leaving the most entangled for last when the team has experience. For each one, we ship the replacement in the internal starter first, with both paths present. A feature switch, a property such as acme.legacy.region-injector.enabled, decides whether the old post-processor runs. We register legacy post-processors through a static @Bean method guarded by that condition, so that turning it off removes it entirely.

We prove equivalence with tests before turning the switch. The bean definition dump from step 1 becomes a test: with the legacy post-processor off and the replacement on, the important beans must have the same effective configuration. Then we flip the switch in one low-risk service, then a group, then everywhere, and delete the old code a release or two later.

Step throughRetiring one post-processor
  1. Pick next post-processordead ones first, most entangled last
  2. Ship standard replacement in the starterold path still on
  3. Add switch and equivalence testsdefinition dump and integration tests
  4. Tests and a pilot service green?
    YesSwitch off for a group, then allNoFix replacement, keep old path
  5. Keep it off for one or two releaseswatch errors per service
  6. Delete the old post-processorand its switch

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

Every step can be undone by flipping one property until the final delete.

6Freeze the Old Framework and Set the Timeline

A migration never ends if the old framework keeps growing. So we freeze it: no new features, only security and critical fixes, with new needs built the standard way in the starter. This needs backing from engineering leadership, otherwise teams keep asking for one more rewrite rule because it is quicker.

The timeline should be anchored to dates nobody can argue with: the end of open-source support for the Spring Boot and Spring Framework versions the services run today, and the dates when the company wants AOT or native images for cost or startup reasons. We check the published support dates and plan backwards: if the current line loses free support in twelve months and thirty post-processors remain, retiring three a month leaves a two-month buffer, tracked as post-processors remaining and services still using each.

7Follow-up questions

Why not just upgrade first and fix the post-processors when they break?

Because a rewritten bean definition fails far from its cause, as a strange startup error or a subtle behaviour change. Mixing that with all the other changes of a major upgrade makes each problem harder. Retiring the post-processors on the current version first makes the upgrade itself routine.

Are BeanFactoryPostProcessors bad in general?

No. They are a supported extension point, and Spring and many libraries use them well. The problem is using them as a general rule engine that silently rewrites application beans. A small number of well-understood post-processors, registered as static @Bean methods so they do not force early creation of other beans, are perfectly fine and can work with AOT as long as their result does not depend on runtime conditions.

8Conclusion

In this answer, we saw why hidden bean definition rewrites block upgrades and AOT, and we planned the framework's retirement by building an inventory of behaviour and dependants, mapping each behaviour to auto-configuration, conditions, @ConfigurationProperties and customisers, retiring post-processors one at a time behind switches with equivalence tests, freezing new features in the old framework, and tying the timeline to the support dates of the versions we are leaving.

What to say in the interviewAbout 70 seconds aloud

Open with

I would treat it as a migration with a clear inventory and a deadline. First I would list what each post-processor really does, by reading the code and also by dumping the bean definitions of each service with the post-processors on and off, so I can see exactly what changes and which services depend on it.

Then, if they want more

Then I would map each behaviour that is still needed to a standard Spring Boot mechanism: values pushed into definitions become @ConfigurationProperties, environment-dependent bean swaps become auto-configuration with conditions in an internal starter, changes to library beans become customiser beans, and naming-rule interception becomes explicit annotations or aspects.

I would retire the post-processors one at a time: ship the replacement, keep the old one behind a property switch, prove equivalence with tests, flip it for a pilot service, then everyone, and delete the old code a release later.

In parallel I would freeze the old framework for new features, and I would set the timeline backwards from the end of support of our current Spring versions, tracking how many post-processors and dependent services remain.

About this answer

Last updated
12 November 2026
Versions it names
Spring Framework 6, 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 "An old in-house framework built on Spring uses dozens of BeanFactoryPostProcessors to...": https://scrivio-interview-library.netlify.app/spring-boot/bean-lifecycle/801780cdd3/