o.s.c.s.ClassPathXmlApplicationContext : Exception encountered during context initialization -
cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'employee' defined in class path resource [applicationConfig.xml]:
Cannot resolve reference to bean 'dept' while setting bean property 'department'
Exception in thread "main" org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'employee' defined in class path resource [applicationConfig.xml]:
Cannot resolve reference to bean 'dept' while setting bean property 'department'
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:377)
at org.code2care.demo.DemoApplication.main(DemoApplication.java:14)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dept' available
We may get the above exception when working with Spring Boot with Config file (applicationConfig.xml) when you have injected a bean using property tag but the reference name is incorrect or the referenced bean does not exists.
Example:<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean name="employee" class="org.code2care.demo.Employee">
<property name="department" ref="dept"/>
</bean>
<bean name="department" class="org.code2care.demo.Department"/>
</beans>
As you can see in my case, the issue is that I have used the reference name as dept instead of department.

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!