Wednesday, August 25, 2021

class path resource [beans.xml] cannot be opened because it does not exist


 

ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");


Caused by: java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exist

at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:187)

at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:333)

... 13 more



Solution:
There are two solutions

1. Take the beans.xml out of package and put in default package.
2. Specify package name of the file..
    ClassPathXmlApplicationContext("com/se/io/beans.xml");