spring-projects/spring-framework · error · AopConfigException
Cannot add advisor: Configuration is frozen.
Error message
Cannot add advisor: Configuration is frozen.
What it means
AdvisedSupport.addAdvisors(Collection) (line 379) refuses to append advisors when the configuration is frozen (isFrozen(), line 380). Frozen means the advisor chain has been locked for optimization/consistency, so no bulk addition is allowed.
Solutions
- Ensure setFrozen(false) (the default) before adding advisors
- If the proxy is already built and frozen, construct a fresh ProxyFactory, copy configuration, add advisors, and create a new proxy
- Check ((Advised) proxy).isFrozen() before attempting the add and report/handle it
Example fix
// before advised.setFrozen(true); advised.addAdvisors(myAdvisors); // after advised.setFrozen(false); advised.addAdvisors(myAdvisors);
Defensive patterns
Strategy: validation
Validate before calling
if (advised.isFrozen()) {
throw new IllegalStateException("Cannot add advisors: configuration is frozen");
}
advised.addAdvisors(advisors); Type guard
private static boolean canAddAdvisor(AdvisedSupport a) {
return a != null && !a.isFrozen();
} Prevention
- Keep frozen=false when runtime mutation is required
- Build a new ProxyFactory if you must change a frozen proxy
When it happens
Trigger: Calling addAdvisors(Collection) or addAdvisors(Advisor...) on a frozen AdvisedSupport instance.
Common situations: Explicitly setFrozen(true) for optimization then later trying to add advisors; mutating an Advised proxy that was built with frozen config; calling addAdvisors on a configuration snapshot taken from an already-built proxy.
Related errors
- Cannot remove Advisor: Configuration is frozen.
- Advisor index is out of bounds: This configuration only has…
- DynamicIntroductionAdvice may only be added as part of…
- Illegal position in advisor list with size
- Cannot get bean name; not set on MethodInvocation
AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09).
Data as JSON: /api/errors/e5088d4d46f4a31f.
Report an issue: GitHub.
Appendix: source
Thrown at spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java:381
addAdvisor(index, b);
return true;
}
/**
* Add all the given advisors to this proxy configuration.
* @param advisors the advisors to register
*/
public void addAdvisors(Advisor... advisors) {
addAdvisors(Arrays.asList(advisors));
}
/**
* Add all the given advisors to this proxy configuration.
* @param advisors the advisors to register
*/
public void addAdvisors(Collection<Advisor> advisors) {
if (isFrozen()) {
throw new AopConfigException("Cannot add advisor: Configuration is frozen.");
}
if (!CollectionUtils.isEmpty(advisors)) {
for (Advisor advisor : advisors) {
if (advisor instanceof IntroductionAdvisor introductionAdvisor) {
validateIntroductionAdvisor(introductionAdvisor);
}
Assert.notNull(advisor, "Advisor must not be null");
this.advisors.add(advisor);
}
adviceChanged();
}
}
private void validateIntroductionAdvisor(IntroductionAdvisor advisor) {
advisor.validateInterfaces();
// If the advisor passed validation, we can make the change.
for (Class<?> ifc : advisor.getInterfaces()) {
addInterface(ifc);View on GitHub (pinned to 69bf83ad71)