欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

BeanFactory not initialized or already closed - call ‘refresh‘ before accessing beans via the Applic

程序员文章站 2024-02-22 11:22:22
...

BeanFactory not initialized or already closed - call ‘refresh’ before accessing beans via the ApplicationContext

我的错误是括号里没写上applicationContext.xml


  public class AccountController {
        public static void main(String[] args) {
            ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");//括号里要写上applicationContext.xml不然运行会报 BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext的类型错误
            AccountService accountService = app.getBean(AccountService.class);
            accountService.transfer("frank","mark",200);
        } 
        }