Eclipse Spring : class path resource cannot be opened because it does not exist

RRR Source

This is not Spring Boot nor MVC. I'm not using Maven, just basic Spring under Eclipse.

I'm new to Spring, followed a YouTube tutorial which dates back to 2011 (many methods the author uses in the video are all deprecated as well as the XML file structure, so I had to adapt them first).

Here's my first (not working) Spring project structure:

In the Triangle class:

public class Triangle {
public void draw(){
    System.out.println("Triangle drawn.\n");

In the spring.xml file:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns = ""
xmlns:xsi = ""

<bean id="tri1" class="com.springDemo.rickyJava.Triangle">


In the main:

public class DrawingAppl {
public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");

    Triangle tri1 = (Triangle) context.getBean("tri1");

    ((ClassPathXmlApplicationContext) context).close();

My project structure is:

My first Spring project structure

I don't understand what could go wrong, the author has the same project structure in his eclipse in the video, but mine just can't find the XML. Error:

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring.xml]; nested exception is class path resource [spring.xml] cannot be opened because it does not exist

Since a lot of people who followed this tutorial got the same problem, I figured it must be something else than the code itself but I cannot find any solution that works for me on the internet. I tried everything I can but nothing worked.



answered 1 month ago Snekhe #1

As per my understanding spring by default uses the resources from src/main/resources folder to add to classpath. There are methods to override this default behavior. For now I would suggest creating the below structure and running it again.It should run flawlessly. Let me know in case you would need any additional help for the same.

enter image description here

comments powered by Disqus