springboot获取上下文 怎么获取Spring的ApplicationContext?
怎么获取Spring的ApplicationContext?方法1:在初始化期间保存ApplicationContext对象。ApplicationContext AC=新文件系统xmlapplica
怎么获取Spring的ApplicationContext?
方法1:在初始化期间保存ApplicationContext对象。ApplicationContext AC=新文件系统xmlapplicationcontext(“应用程序上下文.xml") 交流getBean(“beanid”)此方法适用于使用spring框架的独立应用程序,需要通过配置文件手动初始化spring。方法2:通过spring提供的工具类获取ApplicationContext对象导入org.springframework.web网站. context.support.webapplicationContext应用程序上下文ac1=网络应用程序应用程序上下文。getRequiredWebApplicationContext(ServletContext sc)ApplicationContext ac2=WebAppapplicationContextUtils.getWebApplicationContext(ServletContext sc)ac1.getBean(“beanId”)ac2.getBean(“beanId”)