spring-projects/spring-framework · error · AopConfigException
Target required after globals
Error message
Target required after globals
What it means
In initializeAdvisorChain(), if the last entry of interceptorNames is a global advisor (ends with '*') and no target was supplied (targetName==null and targetSource is empty), Spring cannot build the proxy because globals only contribute advice - the proxy still needs a target. Hence 'Target required after globals'.
Source
Thrown at spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java:418
}
/**
* Create the advisor (interceptor) chain. Advisors that are sourced
* from a BeanFactory will be refreshed each time a new prototype instance
* is added. Interceptors added programmatically through the factory API
* are unaffected by such changes.
*/
private synchronized void initializeAdvisorChain() throws AopConfigException, BeansException {
if (!this.advisorChainInitialized && !ObjectUtils.isEmpty(this.interceptorNames)) {
if (this.beanFactory == null) {
throw new IllegalStateException("No BeanFactory available anymore (probably due to serialization) " +
"- cannot resolve interceptor names " + Arrays.toString(this.interceptorNames));
}
// Globals can't be last unless we specified a targetSource using the property...
if (this.interceptorNames[this.interceptorNames.length - 1].endsWith(GLOBAL_SUFFIX) &&
this.targetName == null && this.targetSource == EMPTY_TARGET_SOURCE) {
throw new AopConfigException("Target required after globals");
}
// Materialize interceptor chain from bean names.
for (String name : this.interceptorNames) {
if (name.endsWith(GLOBAL_SUFFIX)) {
if (!(this.beanFactory instanceof ListableBeanFactory lbf)) {
throw new AopConfigException(
"Can only use global advisors or interceptors with a ListableBeanFactory");
}
addGlobalAdvisors(lbf, name.substring(0, name.length() - GLOBAL_SUFFIX.length()));
}
else {
// If we get here, we need to add a named interceptor.
// We must check if it's a singleton or prototype.
Object advice;
if (this.singleton || this.beanFactory.isSingleton(name)) {
// Add the real Advisor/Advice to the chain.View on GitHub (pinned to e8729d0438)
Solutions
- Set target / targetName / targetSource on the ProxyFactoryBean, OR
- Add the target bean name as the final (non-global) entry of interceptorNames, OR
- Drop the global suffix from interceptorNames and reference advisors explicitly.
Example fix
// before <property name="interceptorNames" value="global*"/> // after <property name="interceptorNames" value="global*"/> <property name="targetName" value="myService"/>
Defensive patterns
Strategy: validation
Validate before calling
String[] names = pfb.getInterceptorNames();
boolean endsWithGlobal = names != null && names.length > 0 && names[names.length - 1].endsWith("*");
boolean hasTarget = pfb.getTargetName() != null || pfb.getTargetSource() != null;
if (endsWithGlobal && !hasTarget) {
throw new IllegalStateException("Global-only interceptorNames require an explicit target on ProxyFactoryBean");
} Prevention
- Always pair global '*' entries with an explicit target/targetName.
- Avoid relying on global advisors as the sole chain member.
- Prefer naming advisors explicitly to make the chain deterministic.
When it happens
Trigger: Configuring interceptorNames ending with a global pattern (e.g. 'global*' or 'foo*') without also providing a target, targetName, or a non-empty targetSource on the ProxyFactoryBean.
Common situations: XML config that relies on global advisors but forgets to wire the target bean; using the legacy global-advisor convention without a concluding target entry.
Related errors
- Can only use global advisors or interceptors with a Listable
- Unknown advisor type {next.getClass()}; can only include Adv
- Cannot determine target class for proxy
- No BeanFactory available anymore (probably due to serializat
- No BeanFactory available anymore (probably due to serializat
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/24b85361eeee5533.json.
Report an issue: GitHub.