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.
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Java,
- Deep Dive into Java 8 Predicate Interface
- Read and Parse XML file using Java DOM Parser [Java Tutorial]
- Java 8 Predicate Functional Interface isEqual() Method Example
- Convert Multidimensional Array toString In Java
- How to read int value using Scanner Class Java
- Spring Boot AI + LLM + Java Code Example
- Write to a File using Java Stream API
- Implementing Bubble Sort Algorithm using Java Program
- How to Fix XmlBeanDefinitionStoreException in Java SpringBoot ApplicationConfig.xml
- YAML Parser using Java Jackson Library Example
- [Fix] java: integer number too large compilation error
- Convert JSON String to Java GSON Object Example
- Read a file using Java 8 Stream
- Java Spring Boot 3 Web Hello World with Gradle in IntelliJ
- Ways Compare Dates in Java Programming with Examples
- Pretty Print JSON String in Java Console Output
- Java JDBC with Join Queries Example
- How to Check For Updates on Windows 11 (Step-by-Step)
- [Fix] java.net.MalformedURLException: unknown protocol
- How to display date and time in GMT Timezone in Java
- Error: LinkageError occurred while loading main class UnsupportedClassVersionError [Eclipse Java]
- How to convert a String to Java 8 Stream of Char?
- RabbitMQ Queue Listener Java Spring Boot Code Example
- 5+ Fibonacci number Series Java Program Examples [ 0 1 1 2 3 ..]
- Handling NullPointerException with Java Predicate
More Posts:
- How to List All Users in Linux - Linux
- Change Font Size in Visual Studio Code - HowTos
- Spring 5 IoC Example with application Context XML (ClassPathXmlApplicationContext) and Gradle. - Java
- Fix: error: invalid command bdist_wheel - Python - Python
- [Solution] AWS Java SDK S3 AmazonS3Exception InvalidAccessKeyId - AWS
- How to Connect to Azure AD Account using PowerShell on Mac - Powershell
- Docker Alpine Linux and Apache2 Example - Docker
- [Fix] Java: Type argument cannot be of primitive type generics - Java