XmlBeanFactory 过时了

jike_9492740 Spring 入门示例 最后由 jike_9492740 于03月31日 19:24回复

  • 2 回答
  • 100 浏览

网上只能找到BeanFactory f = new ClassPathXmlApplicationContext("helloMessage.xml");这个,但是我要的不是这个替代方法,网上找不到

  • jike_9492740 03月31日 19:23 回答 #1楼
  • Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

    at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:164)

    at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:228)

    at org.springframework.context.support.AbstractRefreshableApplicationContext.<init>(AbstractRefreshableApplicationContext.java:89)

    at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.<init>(AbstractRefreshableConfigApplicationContext.java:58)

    at org.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:61)

    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:190)

    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:172)

    at com.jike.spring.chapte01.Main.main(Main.java:17)

    Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory

    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

    ... 8 more

  • 0 评论
  • jike_9492740 03月31日 19:24 回答 #2楼
  • 用了这个方法也出错:

    ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "hellomessage.xml" }, Main.class);

    Resource r = ctx.getResource("hellomessage.xml");

    Person s = ctx.getBean(Person.class);

    // BeanFactory factory = new XmlBeanFactory(r);

    // Person s = (Person) factory.getBean("person");

    String string = s.sayHello();

    System.out.println("" + string);

  • 0 评论