构造方法不对,你可以用下面这种方法取try {
      ApplicationContext ctx = new FileSystemXmlApplicationContext(
          "applicationContext.xml");
      Inter inter=(Inter) ctx.getBean("str");
      inter.hello();
    } catch (Exception e) {
      System.out.println(e.getLocalizedMessage());
    }

解决方案 »

  1.   

    那象你这样不是就没有用BeanFactory对象吗?
      

  2.   

    如果要用BeanFactory那该怎么样写?
      

  3.   

    LZ看的是spring in aciton 吧,他用的BeanFactory factory = new XmlBeanFactory(new FileInputStream("hello.xml"));
    可是现在用的新版本的构造器(XmlBeanFactory)只能接收Resource接口了,所以调不出来是正常的事情,假设现在有一个文件hello.xml
    读取方法
    1:ApplicationContext cx=new FileSystemXmlApplicationContext("hello.xml");//指定的路径去找文件
    2:ApplicationContext factory = new ClassPathXmlApplicationContext("hello.xml");//还会在classpath去找
    3:BeanFactory factory=new XmlBeanFactory(new FileSystemResource("hello.xml"));
    4:这个要设制classpath了,麻烦
    BeanFactory factory=new XmlBeanFactory(new ClassPathResource("com/springinaction/chapter01/hello/hello.xml"));
    上面那种方法都可以调用getBean("your bean name")了,
    eg: BeanFactory factory=new XmlBeanFactory(new FileSystemResource("hello.xml"));
          Hello he=(Hello)factory.getBean("hello");
                  he.getHello();
      

  4.   

    楼上的,你确实说得很有道理,实在是太感谢了,真的,反正我也不知道怎么搞的,觉得spring in action里面是不是有点太老了.FileSystemResource这个是什么类?
      

  5.   

    开源的东东更新的都很快,spring in action还是很值得看的,多么经典的书啊,关键是里面的思想和一些原理。至于FileSystemResource这个类,是spring中的东西,你看下spring的API就知道了。
      

  6.   

    XmlBeanFactory factory=
    new XmlBeanFactory(new FileInputStream("applicationContext.xml"));