日期:2014-05-20  浏览次数:20834 次

Spring的问题
都是招书抄的,为什么会出现问题呢?请教各位
--------------------------------------------------
<?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-2.0.xsd">
<bean id = "helloBean"
class="onlyfun.caterpillar.HelloBean">
<property name = "helloWord">
<value>Hello!Justin!</value>
</property>
</bean>
</beans>
---------------------------------------------------
package onlyfun.caterpillar;

public class HelloBean {
private String helloWord;

public void setHelloWorld(String helloWord) {
this.helloWord = helloWord;
}

public String getHelloWord(){
return helloWord;
}

}


--------------------------------------------------------
package onlyfun.caterpillar;

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

public class SpringDemo {
/**
* @param args
*/
public static void main(String[] args) {
Resource rs = new ClassPathResource("beans-config.xml");
BeanFactory factory = new XmlBeanFactory(rs);
//HelloBean hello = (HelloBean) factory.getBean("helloBean");
//System.out.println(hello.getHelloWord());
System.out.println("ddddddd");

}

}

------------------------------------------------------------

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 [beans-config.xml]; nested exception is java.io.FileNotFoundException: class path resource [beans-config.xml] cannot be opened because it does not exist
Caused by: java.io.FileNotFoundException: class path resource [beans-config.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:307)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:290)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:73)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:61)
at onlyfun.caterpillar.SpringDemo.main(SpringDemo.java:14)



------解决方案--------------------
很明显嘛,没找到beans-config.xml