I just started to learn Spring Framework, installed Eclipse and added Spring and Maven. I made my first program, of course, Hello World but using spring beans. Everything was "by the book", I made some class, let's say Person, and main class that will instantiate it through beans in xml spring beans configuration file. I made beans.xml file right in my project just like in book example, and wrote following code:
package maven.aplikacije.Person;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App
{
public static void main( String[] args )
{
ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
Person helloBean = (Person)ac.getBean("person");
helloBean.sayHello();
}
}
This is a beans.xml
<?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">
<bean id = "person" class = "maven.aplikacije.Person.Person"></bean>
</beans>
However, it does not work. It lists following error (among others):
INFO: Loading XML bean definitions from class path resource [Person/beans.xml] Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [Person/beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [Person/beans.xml] cannot be opened because it does not exist
I tried to write
ApplicationContext ac = new ClassPathXmlApplicationContext("Person//beans.xml");
and plenty more different versions but nothing works. Of course, I also defined Person class. :)
Why doesn't program "see" beans.xml file?
Thank you in advance!
PascalCase
is reserved for class names, please use lower case for package names. - Boris the Spider