How to Fix XmlBeanDefinitionStoreException in Java SpringBoot ApplicationConfig.xml

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(
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(
	at org.code2care.demo.DemoApplication.main(

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=""

    <!-- Spring Config template -->

Spring Config Template to fix XmlBeanDefinitionStoreException

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

This is not an AI-generated article but is demonstrated by a human on an M1 Mac with IntelliJ and Spring Boot.

Please support independent contributors like Code2care by donating a coffee.

Buy me a coffee!

Buy Code2care a Coffee!

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

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:

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap