{"id":"4325d293f5b00989","repo":"spring-projects/spring-framework","slug":"specify-either-targetobject-or-targetbeanname","errorCode":null,"errorMessage":"Specify either 'targetObject' or 'targetBeanName', not both","messagePattern":"Specify either 'targetObject' or 'targetBeanName', not both","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPathFactoryBean.java","lineNumber":164,"sourceCode":"\t/**\n\t * The bean name of this PropertyPathFactoryBean will be interpreted\n\t * as \"beanName.property\" pattern, if neither \"targetObject\" nor\n\t * \"targetBeanName\" nor \"propertyPath\" have been specified.\n\t * This allows for concise bean definitions with just an id/name.\n\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);","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPathFactoryBean.java#L146-L182","documentation":"Error \"Specify either 'targetObject' or 'targetBeanName', not both\" thrown in spring-projects/spring-framework.","triggerScenarios":"Thrown at spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPathFactoryBean.java:164 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}