spring-projects/spring-framework · error · IllegalArgumentException
Property 'target' is required
Error message
Property 'target' is required
What it means
AbstractSingletonProxyFactoryBean (parent of TransactionProxyFactoryBean etc.) requires a 'target' object - the bean to be wrapped by the proxy. afterPropertiesSet() (line 137) throws if target is still null, because a proxy with nothing to delegate to is meaningless. This is a configuration-completeness check fired by the InitializingBean callback.
Solutions
- Call setTarget(targetObject) (or <property name="target" ref="myServiceBean"/> in XML) so the factory has a non-null target
- Confirm the target bean itself is defined and not returning null
- Re-check the factory bean definition after any config refactor to ensure target is still wired
Example fix
// before TransactionProxyFactoryBean fb = new TransactionProxyFactoryBean(); fb.setTransactionManager(txManager); fb.afterPropertiesSet(); // after TransactionProxyFactoryBean fb = new TransactionProxyFactoryBean(); fb.setTarget(myService); fb.setTransactionManager(txManager); fb.afterPropertiesSet();
Defensive patterns
Strategy: validation
Validate before calling
// Programmatic config: validate before afterPropertiesSet()
if (factoryBean.getTarget() == null) {
throw new IllegalStateException("target is required on " + factoryBean.getClass().getSimpleName());
} Type guard
private static boolean hasTarget(AbstractSingletonProxyFactoryBean fb) {
return fb != null && fb.getTarget() != null;
} Prevention
- Write a context-loading test that exercises each TransactionProxyFactoryBean/@Bean definition
- Centralize proxy factory bean construction in a helper that takes a non-null target parameter
When it happens
Trigger: Defining a TransactionProxyFactoryBean (or similar subclass) without setting the target property; programmatic config that forgot setTarget(...); XML missing the <property name="target" .../>.
Common situations: Migrating from ProxyFactoryBean and forgetting the target wiring; a refactored @Bean method that builds the factory bean but drops the setTarget call; XML where the target ref element was accidentally removed.
Related errors
- Property 'methodName' is required
- Property 'targetBeanName' is required
- 'target' needs to be a bean reference, not a bean name as…
- Both 'constructorArgs' and 'constructorArgTypes' need to be…
- Can't determine type of bean with name
AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09).
Data as JSON: /api/errors/6784f9c9a8b7b5e8.
Report an issue: GitHub.
Appendix: 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 69bf83ad71)