{"record":{"id":"6c3fea4d30548dc1","repo":"spring-projects/spring-framework","slug":"neither-targetobject-nor-targetbeanname-specif","errorCode":null,"errorMessage":"Neither 'targetObject' nor 'targetBeanName' specified, and PropertyPathFactoryBean bean name '${beanName}' does not follow 'beanName.property' syntax","messagePattern":"Neither 'targetObject' nor 'targetBeanName' specified, and PropertyPathFactoryBean bean name '(.+?)' does not follow 'beanName\\.property' syntax","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPathFactoryBean.java","lineNumber":176,"sourceCode":"\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\");\n\t\t}\n\n\t\tif (this.targetBeanWrapper == null && StringUtils.hasLength(targetBeanName) &&\n\t\t\t\tthis.beanFactory.isSingleton(targetBeanName)) {\n\t\t\t// Eagerly fetch singleton target bean, and determine result type.\n\t\t\tObject bean = this.beanFactory.getBean(targetBeanName);\n\t\t\tthis.targetBeanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(bean);","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPathFactoryBean.java#L158-L194","documentation":"Thrown by PropertyPathFactoryBean.setBeanFactory() when none of targetObject, targetBeanName, or propertyPath are set, and the factory bean's own bean name does not contain a dot in the 'beanName.property' position. PropertyPathFactoryBean can infer target+path from the bean id (e.g. id 'tb.age'), but only if the id has a dot after position 0; otherwise it has nothing to work with.","triggerScenarios":"A PropertyPathFactoryBean bean with id 'myBean' (no dot) and no properties set. Bean name starting with a dot like '.age' (dotIndex == 0 is rejected). Bean name null (e.g. anonymous/inner registration edge cases).","commonSituations":"Intending the shorthand but giving the bean a plain id without a dot. Forgetting to set targetBeanName/propertyPath AND not naming the bean 'targetBean.property'. XML bean with an id but no inner properties.","solutions":["Rename the bean to follow 'beanName.property', e.g. id=\"tb.age\", and add no other properties.","Or explicitly set targetBeanName and propertyPath on the bean and keep any id you like.","Or set targetObject (inner bean) and propertyPath."],"exampleFix":"<!-- before (broken): id has no dot, no props -->\n<bean id=\"myValue\" class=\"...PropertyPathFactoryBean\"/>\n<!-- after (shorthand) -->\n<bean id=\"tb.age\" class=\"...PropertyPathFactoryBean\"/>","handlingStrategy":"validation","validationCode":"String name = \"tb\"; // intended bean id\nif (targetObject == null && targetBeanName == null && propertyPath == null) {\n    if (name == null || name.indexOf('.') <= 0) {\n        throw new IllegalStateException(\"bean id must be 'beanName.property' when nothing else is set\");\n    }\n}","typeGuard":"static boolean beanNameHasPropertyDot(String beanName) {\n    return beanName != null && beanName.indexOf('.') > 0;\n}","tryCatchPattern":"try {\n    fb.setBeanFactory(beanFactory);\n} catch (IllegalArgumentException ex) {\n    if (ex.getMessage().contains(\"does not follow 'beanName.property' syntax\")) {\n        // rename the bean or set target+propertyPath explicitly\n    }\n    throw ex;\n}","preventionTips":["When using the shorthand, name the bean exactly 'targetBean.property'.","Otherwise set targetBeanName + propertyPath explicitly to avoid naming constraints.","Add a context-load test that exercises each PropertyPathFactoryBean bean id."],"tags":["spring","factory-bean","property-path","configuration","naming"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}