只需要加上这几行就行
static String paths[] = {"spring/applicationContext.xml"};
static ApplicationContext ctx = new ClassPathXmlApplicationContext(paths);
static BookService bookService = ctx.getBean(BookService.class);
本文介绍如何使用Spring框架加载配置文件并获取Bean实例。通过静态初始化方式,加载applicationContext.xml配置文件,创建ClassPathXmlApplicationContext上下文,进而获取BookService Bean实例。
只需要加上这几行就行
static String paths[] = {"spring/applicationContext.xml"};
static ApplicationContext ctx = new ClassPathXmlApplicationContext(paths);
static BookService bookService = ctx.getBean(BookService.class);
1027
1408
2031

被折叠的 条评论
为什么被折叠?