{"record":{"id":"fffe9793083bec82","repo":"spring-projects/spring-framework","slug":"specify-targetobject-or-targetbeanname-in-comb","errorCode":null,"errorMessage":"Specify 'targetObject' or 'targetBeanName' in combination with 'propertyPath'","messagePattern":"Specify 'targetObject' or 'targetBeanName' in combination with 'propertyPath'","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPathFactoryBean.java","lineNumber":169,"sourceCode":"\t */\n\t@Override\n\tpublic void setBeanName(String beanName) {\n\t\tthis.beanName = StringUtils.trimAllWhitespace(BeanFactoryUtils.originalBeanName(beanName));\n\t}\n\n\n\t@Override\n\tpublic void setBeanFactory(BeanFactory beanFactory) {\n\t\tthis.beanFactory = beanFactory;\n\t\tString targetBeanName = this.targetBeanName;\n\n\t\tif (this.targetBeanWrapper != null && targetBeanName != null) {\n\t\t\tthrow new IllegalArgumentException(\"Specify either 'targetObject' or 'targetBeanName', not both\");\n\t\t}\n\n\t\tif (this.targetBeanWrapper == null && targetBeanName == null) {\n\t\t\tif (this.propertyPath != null) {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\"Specify 'targetObject' or 'targetBeanName' in combination with 'propertyPath'\");\n\t\t\t}\n\n\t\t\t// No other properties specified: check bean name.\n\t\t\tint dotIndex;\n\t\t\tif (this.beanName == null || (dotIndex = this.beanName.indexOf('.')) <= 0) {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\"Neither 'targetObject' nor 'targetBeanName' specified, and PropertyPathFactoryBean \" +\n\t\t\t\t\t\t\"bean name '\" + this.beanName + \"' does not follow 'beanName.property' syntax\");\n\t\t\t}\n\t\t\ttargetBeanName = this.beanName.substring(0, dotIndex);\n\t\t\tthis.targetBeanName = targetBeanName;\n\t\t\tthis.propertyPath = this.beanName.substring(dotIndex + 1);\n\t\t}\n\n\t\telse if (this.propertyPath == null) {\n\t\t\t// either targetObject or targetBeanName specified\n\t\t\tthrow new IllegalArgumentException(\"'propertyPath' is required\");","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPathFactoryBean.java#L151-L187","documentation":"Thrown by PropertyPathFactoryBean.setBeanFactory() when a propertyPath has been supplied but neither targetObject nor targetBeanName was set. The property path needs a target to be evaluated against; without a target Spring cannot infer one (unlike the bean-name shorthand, propertyPath alone does not carry the bean name).","triggerScenarios":"XML with only <property name=\"propertyPath\" value=\"age\"/> and no target. Programmatic setPropertyPath(\"age\") without setTargetObject/setTargetBeanName. Intent to use the bean-name shorthand but accidentally also setting propertyPath.","commonSituations":"Misunderstanding that the 'beanName.property' shorthand works only when NOTHING else is set; adding propertyPath disables the shorthand. Partial migration between the two forms.","solutions":["Add targetBeanName (e.g. <property name=\"targetBeanName\" value=\"tb\"/>) alongside propertyPath.","Or add targetObject (an inner bean or ref) alongside propertyPath.","If you wanted the bean-name shorthand, remove the propertyPath property and rely on the bean id 'tb.age'."],"exampleFix":"<!-- before (broken) -->\n<bean id=\"x\" class=\"...PropertyPathFactoryBean\">\n  <property name=\"propertyPath\" value=\"age\"/>\n</bean>\n<!-- after -->\n<bean id=\"x\" class=\"...PropertyPathFactoryBean\">\n  <property name=\"targetBeanName\" value=\"tb\"/>\n  <property name=\"propertyPath\" value=\"age\"/>\n</bean>","handlingStrategy":"validation","validationCode":"if (propertyPath != null && targetObject == null && targetBeanName == null) {\n    throw new IllegalStateException(\"propertyPath requires a targetObject or targetBeanName\");\n}","typeGuard":"static boolean pathHasTarget(String propertyPath, String targetBeanName, Object targetObject) {\n    return propertyPath == null || targetObject != null || targetBeanName != null;\n}","tryCatchPattern":"try {\n    fb.setBeanFactory(beanFactory);\n} catch (IllegalArgumentException ex) {\n    if (ex.getMessage().contains(\"in combination with 'propertyPath'\")) {\n        // add targetBeanName or targetObject, then retry\n    }\n    throw ex;\n}","preventionTips":["When using propertyPath explicitly, always pair it with targetBeanName or targetObject.","If you want the bean-name shorthand, set ONLY the bean id and nothing else.","Document the three valid PropertyPathFactoryBean configuration forms for your team."],"tags":["spring","factory-bean","property-path","configuration","missing-property"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}