{"id":"6784f9c9a8b7b5e8","repo":"spring-projects/spring-framework","slug":"property-target-is-required","errorCode":null,"errorMessage":"Property 'target' is required","messagePattern":"Property 'target' is required","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java","lineNumber":138,"sourceCode":"\t * containing BeanFactory for loading all bean classes. This can be\n\t * overridden here for specific proxies.\n\t */\n\tpublic void setProxyClassLoader(ClassLoader classLoader) {\n\t\tthis.proxyClassLoader = classLoader;\n\t}\n\n\t@Override\n\tpublic void setBeanClassLoader(ClassLoader classLoader) {\n\t\tif (this.proxyClassLoader == null) {\n\t\t\tthis.proxyClassLoader = classLoader;\n\t\t}\n\t}\n\n\n\t@Override\n\tpublic void afterPropertiesSet() {\n\t\tif (this.target == null) {\n\t\t\tthrow new IllegalArgumentException(\"Property 'target' is required\");\n\t\t}\n\t\tif (this.target instanceof String) {\n\t\t\tthrow new IllegalArgumentException(\"'target' needs to be a bean reference, not a bean name as value\");\n\t\t}\n\t\tif (this.proxyClassLoader == null) {\n\t\t\tthis.proxyClassLoader = ClassUtils.getDefaultClassLoader();\n\t\t}\n\n\t\tProxyFactory proxyFactory = new ProxyFactory();\n\n\t\tif (this.preInterceptors != null) {\n\t\t\tfor (Object interceptor : this.preInterceptors) {\n\t\t\t\tproxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(interceptor));\n\t\t\t}\n\t\t}\n\n\t\t// Add the main interceptor (typically an Advisor).\n\t\tproxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(createMainInterceptor()));","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java#L120-L156","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n<bean id=\"txProxy\" class=\"org.springframework.transaction.interceptor.TransactionProxyFactoryBean\">\n  <property name=\"transactionManager\" ref=\"tm\"/>\n  <!-- target missing -->\n</bean>\n\n// after\n<bean id=\"txProxy\" class=\"org.springframework.transaction.interceptor.TransactionProxyFactoryBean\">\n  <property name=\"transactionManager\" ref=\"tm\"/>\n  <property name=\"target\" ref=\"myService\"/>\n</bean>","handlingStrategy":"validation","validationCode":"// Before letting the container initialize the FactoryBean:\nAbstractSingletonProxyFactoryBean fb = ...; // e.g. TransactionProxyFactoryBean\nif (fb.getTarget() == null) {  // note: target is private; use the public accessor or assertion on your wiring\n  throw new IllegalStateException(\"target not set on \" + fb.getClass().getSimpleName());\n}\n// In practice, enforce this via your config layer / a BeanPostProcessor check.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["spring-aop","configuration","proxy","required-property"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}