错误原因:BeanFactory没有实例化或者已经关闭。原因很简单:ApplicationContext ctx = new ClassPathXmlApplicationContext();Spring实例化BeanFactory的时候是默认到classPath下面查找名为applicationContext.xml的文件。这正是这个错误的原因,修改为:ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");如果这样的话就不会出现这样的错误了。applicationContext.xml,,,,可以是自己命名的xml来自网络:http://blog.sina.com.cn/s/blog_80e498b10100w10b.html
ApplicationContext ctx = new ClassPathXmlApplicationContext();
UserService service = (UserService)ctx.getBean("bean.xml");
我就是ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");这样配置的哦,不是这个原因
你这样使用,每次使用都会重启服务的。
我就是ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");这样配置的哦,不是这个原因其实我也不太懂,所以才去网上帮你搜答案, applicationContext.xml为啥不用 web.xml去配置,而要这样去获取呢