文章詳情頁
Spring如何使用xml創(chuàng)建bean對象
瀏覽:247日期:2023-08-22 16:07:14
一、導(dǎo)入JAR包

二、配置applicationContext.xml的spring核心配置

三、
public static void main(String[] args) { //1.使用 ApplicationContext 接口,就是在獲取 spring 容器 ApplicationContext ac = new ClassPathXmlApplicationContext('bean.xml'); //2.根據(jù) bean 的 id 獲取對象 IAccountService aService = (IAccountService) ac.getBean('accountService'); System.out.println(aService); IAccountDao aDao = (IAccountDao) ac.getBean('accountDao'); System.out.println(aDao); }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
標(biāo)簽:
Spring
相關(guān)文章:
排行榜

網(wǎng)公網(wǎng)安備