spring獲取bean的幾種方式 怎么取出spring的bean?
怎么取出spring的bean?通過xml配置文件bean配置在xml里面,spring提供多種方式讀取配置文件得到ApplicationContext.第一種方式:FileSystemXmlAppl
怎么取出spring的bean?
通過xml配置文件bean配置在xml里面,spring提供多種方式讀取配置文件得到ApplicationContext.第一種方式:FileSystemXmlApplicationContext通過程序在初始化的時(shí)候,導(dǎo)入Bean配置文件,然后得到Bean實(shí)例:ApplicationContext ac = new FileSystemXmlApplicationContext(applicationContext.xml)ac.getBean(beanName)第二種方式:WebApplicationContextUtil在B/S系統(tǒng)中,通常在web.xml初始化bean的配置文件,然后由WebAppliCationContextUtil得到ApplicationContext.例如:ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletContext sc)ApplicationContext ctx =