博主最近刚开始接触了Spring框架,用的还不是特别到熟,经常会碰到错误,下面给大家分享一下博主遇到的小问题
抛出问题
Exception in thread "main" java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:170)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973)
at com.wanbang.autowire.Main.main(Main.java:10)
以上是控制台报错信息
接下来我们来看一下main方法
小伙伴们有发现什么错误吗?是的,我们没有传入xml文件为参数到ClassPathXmlApplicationContext方法中,初学者是不是很容易忘记呀!
现在我们加上xml文件
这样就解决这个问题了
小结
对于Spring初学者来说,还是要多敲,才能把握住小细节