applicationcontext?applicationcontext作用
applicationContext.xml和SpringMVC的区别
applicationContext.xml是文件,是Spring的配置文件SpringMVC是web架构方式,包含了Spring
spring boot项目中怎么获取ConfigurableApplicationContext对象
springboot项目中想要获取ConfigurableApplicationContext对象,可以这么操作:
直接注入@ComponentpublicclassMyClass{@AutowiredprivateApplicationContextapplicationContext;}
怎么获取Spring的ApplicationContext
方法一:在初始化时保存ApplicationContext对象ApplicationContextac=newFileSystemXmlApplicationContext("applicationContext.xml");ac.getBean("beanId");这种方式适用于采用Spring框架的独立应用程序,需要程序通过配置文件手工初始化Spring的情况。方法二:通过Spring提供的工具类获取ApplicationContext对象importorg.springframework.web.context.support.WebApplicationContextUtils;ApplicationContextac1=WebApplicationContextUtils.getRequiredWebApplicationContext(ServletContextsc);ApplicationContextac2=WebApplicationContextUtils.getWebApplicationContext(ServletContextsc);ac1.getBean("beanId");ac2.getBean("beanId");





