解决方案 »

  1.   

    NoClassDefFoundError
    说你没有定义bean,你确定beans-config.xml放的位置正确,能正常初始化XmlBeanFactory?
      

  2.   

    配置文件时,要认真点:
    <bean id="helloBean" class="onlyfun.caterpillar.Hellobean">
    class配错了,认真看看。log4j那些警告不影响使用,要配正确的话,需要在classPath中加入 log4j.properties文件,文件内容可以百度一下。
    可能还需要初始化 log4j,这个忘记了是不是必须的。
      

  3.   

    劝你还是重sping3或4学起吧,太老的东西有的都淘汰了,等你学完还得尝试忘记学过的东西。。
      

  4.   

    学学spring4吧,功能太强大了,很好
      

  5.   

    各位有什么好点的书籍推荐一下?关于spring4的,我是菜,从入门开始
      

  6.   

    <bean id="helloBean" class="onlyfun.caterpillar.Hellobean">
      

  7.   

    public class SpringDemo {
     
        /**
         * @param args
         */
        public static void main(String[] args) {        ApplicationContext  ct= new ClassPathResource("applicationContext.xml"); ///创建此对象         
            HelloBean hello = (HelloBean) ct.getBean("helloBean");
            System.out.println(hello.getHelloword());
        }
     
    }
    ////这个才是正确的获取applicationContext.xml配置文件中的内容
      

  8.   


    NoClassDefFoundError  这个错误常见有两种情况:
    1、我们搞错了大小写,Java 区分大小写但 Windows 操作系统不区分大小写,因此经常出现 class found 但却 No def 错误。
    2、我们在第一次访问这个类时它的某个 static 变量赋值时出现了 exception 未处理或者 static {} 块中抛出异常,这就导致这个 found 但 no def,当代码第2次再来尝试访问这个类时就得到 NoClassDefFoundError 。