log4j:WARN No appenders could be found for logger (org.springframework.beans.factory.xml.XmlBeanDefinitionReader).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Passed-in Resource [resource loaded through InputStream] contains an open stream: cannot determine validation mode automatically. Either pass in a Resource that is able to create fresh streams, or explicitly specify the validationMode on your XmlBeanDefinitionReader instance.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.detectValidationMode(XmlBeanDefinitionReader.java:457)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.getValidationModeForResource(XmlBeanDefinitionReader.java:438)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:395)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:73)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:61)
at person.BeanTest.main(BeanTest.java:20)报错
配置文件:<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"><bean id="chinese" class="person.Chinese"/>
   <property   name="axe">
      <ref local="steelAxe"/>
      </property>
      
 </bean>
  <!--
  <property name="num" value="12"/>
            
 -->
 
<bean id="steelAxe" class="person.SteelAxe"  /></beans>
代码:
package person;import java.io.FileInputStream;
import java.io.InputStream;import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.InputStreamResource;public class BeanTest { /**
 * @param args
 */
public static void main(String[] args) throws Exception  {
InputStream is =new FileInputStream("applicationContext.xml");

InputStreamResource isr=new InputStreamResource(is);


XmlBeanFactory factory =new XmlBeanFactory(isr);


System.out.println(" shilihua  BeanFactory");
Person p=(Person)factory.getBean("chinese");
System.out.println(" shilihua  BeanFactory");
p.useAxe();
}

}

解决方案 »

  1.   

    InputStream is =new FileInputStream("applicationContext.xml"); 变为InputStream is =new FileInputStream("classpath:/applicationContext.xml");
      

  2.   

    改了之后就变成   
    Exception in thread "main" java.io.FileNotFoundException: classpath:\applicationContext.xml (文件名、目录名或卷标语法不正确。)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at person.BeanTest.main(BeanTest.java:15)
    还是不对啊
      

  3.   

    BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
    Person p=(Person)factory.getBean("chinese");试试这个