spring-projects/spring-framework · error · IllegalArgumentException
Property 'target' is required
Error message
Property 'target' is required
What it means
Thrown by AbstractSingletonProxyFactoryBean.afterPropertiesSet when the 'target' property was never set on the FactoryBean. This class is the base of TransactionProxyFactoryBean, AsyncAnnotationBeanPostProcessor helpers, RmiProxyFactoryBean-style beans, etc., and the target object to be proxied is mandatory. Spring validates required properties before attempting proxy construction to fail fast with a clear message rather than an obscure NullPointerException later.
Source
Thrown at spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java:138
* containing BeanFactory for loading all bean classes. This can be
* overridden here for specific proxies.
*/
public void setProxyClassLoader(ClassLoader classLoader) {
this.proxyClassLoader = classLoader;
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
if (this.proxyClassLoader == null) {
this.proxyClassLoader = classLoader;
}
}
@Override
public void afterPropertiesSet() {
if (this.target == null) {
throw new IllegalArgumentException("Property 'target' is required");
}
if (this.target instanceof String) {
throw new IllegalArgumentException("'target' needs to be a bean reference, not a bean name as value");
}
if (this.proxyClassLoader == null) {
this.proxyClassLoader = ClassUtils.getDefaultClassLoader();
}
ProxyFactory proxyFactory = new ProxyFactory();
if (this.preInterceptors != null) {
for (Object interceptor : this.preInterceptors) {
proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(interceptor));
}
}
// Add the main interceptor (typically an Advisor).
proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(createMainInterceptor()));View on GitHub (pinned to e8729d0438)
Solutions
- Add the required target property pointing at the bean to be proxied, e.g. <property name="target" ref="myServiceBean"/>.
- If configuring programmatically, call factoryBean.setTarget(theTargetInstance) before the container initializes it (or before manually calling afterPropertiesSet).
- Double-check the target is a real bean reference (ref=), not a string literal (value=), which triggers error 63 instead.
- For FactoryBean subclasses, ensure the subclass's createMainInterceptor() also resolves correctly since target validation runs first.
Example fix
// before <bean id="txProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager" ref="tm"/> <!-- target missing --> </bean> // after <bean id="txProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager" ref="tm"/> <property name="target" ref="myService"/> </bean>
Defensive patterns
Strategy: validation
Validate before calling
// Before letting the container initialize the FactoryBean:
AbstractSingletonProxyFactoryBean fb = ...; // e.g. TransactionProxyFactoryBean
if (fb.getTarget() == null) { // note: target is private; use the public accessor or assertion on your wiring
throw new IllegalStateException("target not set on " + fb.getClass().getSimpleName());
}
// In practice, enforce this via your config layer / a BeanPostProcessor check. Prevention
- Treat the 'target' property as mandatory in config reviews for any AbstractSingletonProxyFactoryBean subclass.
- Prefer annotation-based (@Transactional, @Async) over XML TransactionProxyFactoryBean to avoid manual target wiring.
- Add an integration test that the context starts; missing required properties fail fast at startup.
When it happens
Trigger: Declaring a bean that subclasses AbstractSingletonProxyFactoryBean (e.g. TransactionProxyFactoryBean) in XML/Java config without a <property name="target" ref="..."/> or setTarget(...) call. Also when programmatic config forgets to call setTarget before afterPropertiesSet is invoked by the container.
Common situations: Removing the target property during refactoring; copy-pasting a FactoryBean definition and dropping the target line; accidentally wiring target as a value rather than ref so it ends up null; initializing the bean manually without calling afterPropertiesSet.
Related errors
- MethodInvocation is not a Spring ProxyMethodInvocation: {}
- [{}] is not an interface
- Could not generate CGLIB subclass of {advised.getTargetClass
- Not running in a ConfigurableBeanFactory: {beanFactory}
- 'argumentNames' property of AbstractAspectJAdvice contains a
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/6784f9c9a8b7b5e8.json.
Report an issue: GitHub.