class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: cla

  

CH10.Spring 框架的开发与应用

package src.com.qdu.sun.Spring;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

public class SpringTest {
  public static void main( String[] args ){
         BeanFactory factory = new XmlBeanFactory( new ClassPathResource("applicationContext.xml") );
         HelloWorld gc = (HelloWorld)factory.getBean("greetingService");
         gc.sayGreeting();
     }
}

log4j:WARN No appenders could be found for logger (org.springframework.util.ClassUtils).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from

class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource

[applicationContext.xml] cannot be opened because it does not exist
Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
 at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:135)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:297)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:280)
 at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:73)
 at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:61)
 at src.com.qdu.sun.Spring.SpringTest.main(SpringTest.java:9)

修改为:

public class SpringTest {
  public static void main( String[] args ){
         BeanFactory factory = new XmlBeanFactory( new ClassPathResource("src/applicationContext.xml") );

 

输出:

log4j:WARN No appenders could be found for logger (org.springframework.util.ClassUtils).
log4j:WARN Please initialize the log4j system properly.
you yi ge greeting

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭