学Spring的时候,创建了一个resource目录,来放spring的xml配置文件。但是spring报错,找不到xml配置文件。
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [chapter2/helloworld.xml]; nested exception is java.io.FileNotFoundException: class path resource [chapter2/helloworld.xml] cannot be opened because it does not exist
目录结构如下:
实例化IOC容器的代码:ApplicationContext context = new ClassPathXmlApplicationContext("helloworld.xml");
后来尝试把helloworld.xml放在src目录和resource目录下都可以(不在包中)。于是把代码改成:
ApplicationContext context = new ClassPathXmlApplicationContext("chapter2/helloworld.xml");
问题解决。