报错:java.lang.IllegalStateException: BeanFactory not initialized or already closed - call ‘refresh‘ b

报错:

java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

原因:
在根据依赖文件配置spring容器的时,没有指定依赖文件是哪个:

ClassPathXmlApplicationContext ioc = new ClassPathXmlApplicationContext();

正确写法:

        ClassPathXmlApplicationContext ioc = new ClassPathXmlApplicationContext("beans.xml");

此时要保证beans.xml文件在src目录下.

你可能感兴趣的:(java,python,开发语言)