If you are using the SpringBoot framework with the Spring Config file, then the XML bean definition of the file should have the correct namespaces and schema locations. If they are not correct you will likely see an XmlBeanDefinitionStoreException as shown below.
Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
Line 4 in XML document from class path resource [applicationConfig.xml] is invalid
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:411)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:347)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:319)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:184)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:130)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:95)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:713)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:595)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:144)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:85)
at org.code2care.demo.DemoApplication.main(DemoApplication.java:14)
Caused by: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 133; cvc-elt.1.a:
Cannot find the declaration of element 'beans'.
As you can see in the above stack trace the beans declaration is not found.
To fix this issue, make sure that the template for the Spring Config file is the correct one as below.
Valid Spring Config file template:<?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">
<!-- Spring Config template -->
</beans>
![Spring Config Template to fix XmlBeanDefinitionStoreException Spring Config Template to fix XmlBeanDefinitionStoreException](https://code2care.org/q/fix-xml-bean-definition-storage-exception-in-java-spring-boot-application-config-xml-file/images/Spring Config Template to fix XmlBeanDefinitionStoreException.jpg)
Note: If you make use of IDE such as IntelliJ, you can get this template by navigating to New -> XML Configuration File -> Spring Config from the resources folder.
![IntelliJ - Spring Config File IntelliJ - Spring Config File](https://code2care.org/q/fix-xml-bean-definition-storage-exception-in-java-spring-boot-application-config-xml-file/images/IntelliJ - Spring Config File.jpg)
Facing issues? Have Questions? Post them here! I am happy to answer!
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
- Get the current timestamp in Java
- Java Stream with Multiple Filters Example
- Java SE JDBC with Prepared Statement Parameterized Select Example
- Fix: UnsupportedClassVersionError: Unsupported major.minor version 63.0
- [Fix] Java Exception with Lambda - Cannot invoke because object is null
- 7 deadly java.lang.OutOfMemoryError in Java Programming
- How to Calculate the SHA Hash Value of a File in Java
- Java JDBC Connection with Database using SSL (https) URL
- How to Add/Subtract Days to the Current Date in Java
- Create Nested Directories using Java Code
- Spring Boot: JDBCTemplate BatchUpdate Update Query Example
- What is CA FE BA BE 00 00 00 3D in Java Class Bytecode
- Save Java Object as JSON file using Jackson Library
- Adding Custom ASCII Text Banner in Spring Boot Application
- [Fix] Java: Type argument cannot be of primitive type generics
- List of New Features in Java 11 (JEPs)
- Java: How to Add two Maps with example
- Java JDBC Transition Management using PreparedStatement Examples
- Understanding and Handling NullPointerException in Java: Tips and Tricks for Effective Debugging
- Steps of working with Stored Procedures using JDBCTemplate Spring Boot
- Java 8 java.util.Function and BiFunction Examples
- The Motivation Behind Generics in Java Programming
- Get Current Local Date and Time using Java 8 DateTime API
- Java: Convert Char to ASCII
- Deep Dive: Why avoid java.util.Date and Calendar Classes
- 35: Python Program to find the System Hostname - Python-Programs
- How to enable Auto-Save Files in VS Code - HowTos
- How to Set Background Wallpaper on macOS 13 Ventura - MacOS
- Android Studio Error:(19, 0) Gradle DSL method not found: android() - Android-Studio
- RabbitMQ Java Spring Boot Application Properties List - Java
- Cannot load PowerApps form in SharePoint Online due to repeated authentication - SharePoint
- Disable Startup Sound on macOS - MacOS
- INVALID FILE NAME: MUST CONTAIN ONLY [a-z0-9_.] Android Eclipse Error - Eclipse