IntelliJ Bean XML ClassPath Configuration Error - Spring

ConfigPath Error - FileNotFoundException because bean.xml file does not exist

IntelliJ Bean XML ClassPath Configuration Error - Spring

Subscribe to my newsletter and never miss my upcoming articles

Listen to this article

When compared to Eclipse and NetBeans, the IntelliJ IDE is considered one of the most sophisticated and user-friendly IDEs. Regardless of the fact that Eclipse is the most widely used IDE for Java development, its user experience is poor and antiquated, and it lacks many of the functionalities that IntelliJ offers.

You might presume that all IDEs are the similar, with the exception of feature sets and user interfaces. Not at all. To have a project run well in certain IDEs, you must do certain configurations in each.

In most tutorials and trainings, the instructor will teach you how to build a project using Spring Framework with Eclipse IDE, but what if you wish to use IntelliJ IDEA to build Spring Projects?

If you execute the Main Program in IntelliJ Maven - Spring Project after creating all the required program files, just like in Eclipse, you will get a error like this snippet.

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [springproject/personinfo/person.xml]; nested exception is java.io.FileNotFoundException: class path resource [springproject/personinfo/person.xml] cannot be opened because it does not exist
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:612)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:513)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at springproject.personinfo.Main.main(Main.java:8)

To resolve this error, you must need to configure the ClassPath for your project in a specific way IntelliJ understands.

1.Navigate to the pom.xml file.

Screenshot 2021-08-04 135435.png

2.Insert this code snippet inside the build tag of the pom.xml file.

<!-- IntelliJ IDE needs the following configuration to read the src directory -->
      <resources>
          <resource>
              <directory>${basedir}/src</directory>
              <includes>
                  <include>**/*.properties</include>
                  <include>**/*.xml</include>
              </includes>
          </resource>
      </resources>

3.Refract all your .xml files to a new folder called resources under main folder in src directory of your project.

Screenshot 2021-08-04 141113.png

Tadaaaaaaaaaaaaaaa ! Your Spring Project will now run without errors in IntelliJ. ❤🤟🏻

Meet you in the next article.

வாழ்க தமிழ் ! வளர்க தமிழினம் ! 🟥🟨

 
Share this
Proudly part of