{"record":{"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":"validation","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/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java#L120-L156","documentation":"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.","triggerScenarios":"Defining a TransactionProxyFactoryBean (or similar subclass) without setting the target property; programmatic config that forgot setTarget(...); XML missing the <property name=\"target\" .../>.","commonSituations":"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.","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"],"exampleFix":"// before\nTransactionProxyFactoryBean fb = new TransactionProxyFactoryBean();\nfb.setTransactionManager(txManager);\nfb.afterPropertiesSet();\n\n// after\nTransactionProxyFactoryBean fb = new TransactionProxyFactoryBean();\nfb.setTarget(myService);\nfb.setTransactionManager(txManager);\nfb.afterPropertiesSet();","handlingStrategy":"validation","validationCode":"// Programmatic config: validate before afterPropertiesSet()\nif (factoryBean.getTarget() == null) {\n  throw new IllegalStateException(\"target is required on \" + factoryBean.getClass().getSimpleName());\n}","typeGuard":"private static boolean hasTarget(AbstractSingletonProxyFactoryBean fb) {\n  return fb != null && fb.getTarget() != null;\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["spring-aop","config","proxy-factory","missing-property"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}