Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

Your company adopted AspectJ load-time weaving ten years ago for auditing and it now slows startup and blocks native images. How do you decide what to do?

I would not decide by opinion. First I would measure what load-time weaving costs us today in startup time, build complexity and upgrade pain, then list what each aspect actually does. Most auditing aspects can move to Spring AOP proxies, framework hooks such as Hibernate event listeners, or plain explicit calls; weaving stays only where we truly must advise objects Spring does not manage. We migrate one aspect at a time behind tests that check the audit records, and remove the weaving agent once nothing needs it.

Why this question is asked

Ten-year-old infrastructure decisions are a classic leadership problem: the original reason was sound, the people who made it may have left, and the cost has grown quietly. AspectJ load-time weaving rewrites classes as the JVM loads them, which once was the easiest way to audit every save and every call. Today it adds seconds to startup and it cannot work in a GraalVM native image, where there is no class loading at run time to hook into. Interviewers ask this to see whether we can turn a vague complaint into a plan with evidence, risk control and an end state. In this answer, we will recap what load-time weaving does, measure its cost, sort the aspects into groups, plan the migration with audit tests, and decide when to remove the agent.

1A Quick Recap of Load-Time Weaving

An aspect is a piece of code that runs around other code without that code calling it, for example writing an audit row every time a service method changes data. Spring AOP applies aspects by wrapping Spring beans in proxies, wrapper objects generated at startup that intercept calls from outside. AspectJ goes further: it weaves, meaning it rewrites the bytecode of the target classes themselves so the advice runs inside them.

Load-time weaving, usually shortened to LTW, does that rewriting while the JVM loads each class. It needs a Java agent, for example -javaagent:aspectjweaver.jar on the command line, and an aop.xml file that says which aspects apply to which packages. Because it changes real classes, it can advise anything: private methods, constructors, field writes, and objects created with new that Spring never sees. That power is why a team chose it ten years ago, and it is also the source of today's cost: every class the JVM loads is inspected and possibly rewritten, and a native image, which is compiled ahead of time with no dynamic class loading, has no place for an agent to run.

2Measuring What the Weaving Costs Today

Before proposing anything, we need numbers that the people paying the cost will recognise. The first number is startup time with and without the agent. We can start the same service twice in a test environment, once with the agent and once without it and with auditing disabled, and compare the time until the readiness probe passes. In many systems the difference is several seconds, and for a service that scales out under load those seconds are lost capacity.

The second number is build and operations complexity: how many deployment descriptors, container images and run scripts carry the agent flag, how often an aop.xml mistake has broken an environment, and how many hours the last JDK or Spring upgrade spent on weaver compatibility. The third is what the weaving blocks, which here is native images and possibly faster JVM startup features such as the AOT cache. Writing these down turns 'it is slow' into a cost per year that can be weighed against the migration effort.

3Sorting the Aspects Into Groups

The next step is an inventory. For each aspect we write down its pointcut, the expression that selects where it applies, what it records, and what kind of object it advises. This usually shows that a ten-year-old auditing module is not one thing but several, and that each has a cheaper home today.

Where each kind of audit aspect can move
What the aspect doesBetter home todayWhy
Audits public service methods on Spring beansSpring AOP @Aspect proxySame advice, no agent, works with Spring AOT
Audits entity inserts, updates, deletesHibernate event listener or JPA callbacksThe ORM already knows every change
Records who changed an entity and whenSpring Data JPA auditing or EnversBuilt-in and well tested
Audits a few critical business actionsExplicit auditService.record(...) callVisible in code, easy to review
Advises objects created with new or field writesKeep weaving, or compile-time weavingProxies cannot reach these
Most audit aspects have a home that needs no Java agent; only the last row really requires weaving.

Notice that only the last row truly needs bytecode weaving. Advice on Spring beans works the same with a proxy, as long as we accept the proxy rule that calls a bean makes to itself are not intercepted. Changes to entities are better captured by the persistence layer, because Hibernate fires an event for every insert, update and delete regardless of which code path caused it. And for the handful of actions that auditors care about most, an explicit call is often the best option: the audit is part of the business code, and a reviewer can see it.

If a few aspects really must advise non-Spring objects, we still have a choice between keeping load-time weaving for that one service and switching to compile-time weaving with the AspectJ compiler, which rewrites the classes during the build. Compile-time weaving produces ordinary bytecode, so it needs no agent at startup and does not block native images in the same way.

4Migrating One Aspect at a Time

Auditing is a compliance feature, so the migration must prove that nothing is lost. The safest way is to write the safety net first: tests that perform a business action and then assert the exact audit records that appear, with user, action, entity id and timestamp. We run these tests against the current woven build so they describe today's behaviour, and keep them green through every step.

Java
@SpringBootTest
class OrderAuditTest {
@Autowired OrderService orders;
@Autowired AuditRepository audit;
@Test
@WithMockUser("alice")
void cancellingAnOrderWritesOneAuditRecord() {
orders.cancel(42L);
List<AuditRecord> rows = audit.findByEntityId(42L);
assertThat(rows).hasSize(1); // passes with weaving and after migration
assertThat(rows.get(0).action()).isEqualTo("CANCEL");
assertThat(rows.get(0).user()).isEqualTo("alice");
}
}

With the tests in place, we move one aspect, for example the service-method audit, to a Spring AOP aspect, remove its entry from aop.xml, and ship. If the tests and a period in production show the same audit volume, we move the next one.

But there is a catch: duplicates. During the migration, an aspect must never be active both as a woven aspect and as a proxy aspect, or every action is audited twice. Removing the aop.xml entry in the same change that adds the new aspect avoids this.

5Removing the Agent and Keeping It Gone

When the inventory shows no remaining woven aspects, we remove the -javaagent flag from the platform's base images and run scripts, delete aop.xml and the weaver dependency, and measure startup again to report the gain. Removing it from the shared platform matters: as long as the agent is in the base image, someone will eventually add a new aop.xml entry and the cost returns.

If one or two services still need weaving, the agent becomes an explicit opt-in for those services rather than a platform default, and their owners know that native images are not available to them. That is a reasonable end state, and it is much easier to defend than either a big-bang rewrite or doing nothing.

Step throughDeciding the future of the weaving agent
  1. Measure startup, build and upgrade costwith and without the agent
  2. List every aspect and what it advisespointcut, target type, records written
  3. Does it advise non-Spring objects?
    YesKeep weaving for it, or use compile-time weavingNoMove it to a proxy, listener or explicit call
  4. Migrate one aspect behind audit testsremove its aop.xml entry in the same change
  5. Anything still woven?
    YesAgent becomes opt-in for those servicesNoRemove the agent from the platform

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

6Follow-up questions

Is moving audit code from aspects to explicit calls a step backwards?

Not for the few actions that matter most. Aspects are good for behaviour that is truly uniform, such as timing every method. Audit records for business actions usually need business context, such as the old and new status, and an explicit call makes that context visible and reviewable. Hiding a compliance requirement in a pointcut that nobody reads is a risk in its own right.

How do you persuade the team that owns the auditing module?

With their own numbers and with their concerns addressed first. I would show the measured startup and upgrade cost, then show that the plan starts by writing tests for the audit records they are responsible for, so the migration can only make their guarantees more explicit. Offering to migrate one aspect together, end to end, usually does more than any document.

7Conclusion

In this answer, we saw how to decide the future of an old load-time weaving setup. We measured its real cost in startup, build complexity and blocked options such as native images, inventoried the aspects and found cheaper homes for most of them in Spring AOP proxies, Hibernate listeners, Spring Data auditing or explicit calls, and kept weaving only for advice on objects Spring does not manage. We migrated aspect by aspect behind tests that assert the audit records, avoided double auditing, and removed the agent from the platform once nothing depended on it.

What to say in the interviewAbout 90 seconds aloud

Open with

I would start by measuring rather than arguing. I would compare startup time with and without the weaving agent, count where the agent and aop.xml are configured, and note what the last upgrades cost us, plus the fact that load-time weaving rules out native images because there is no class loading at run time to hook into.

Then, if they want more

Then I would inventory the aspects: what each pointcut matches and what kind of object it advises. In my experience most audit aspects advise Spring beans or entity changes, so they can move to Spring AOP proxies, Hibernate event listeners, Spring Data auditing, or explicit audit calls for the critical business actions.

Only advice on objects that Spring does not create really needs weaving, and for those I would consider compile-time weaving or keep the agent as an opt-in for that service.

The migration itself would go one aspect at a time, behind tests that perform an action and assert the exact audit rows, written against the current woven build first so they capture today's behaviour. I would remove each aop.xml entry in the same change that adds the replacement so nothing is audited twice, and watch audit volumes in production.

Once nothing needs it, I remove the agent from the base images so the cost cannot creep back, and I report the startup gain to close the loop.

About this answer

Last updated
12 November 2026
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 "Your company adopted AspectJ load-time weaving ten years ago for auditing and it now...": https://scrivio-interview-library.netlify.app/spring-boot/aop/2635551560/